@@ -25,86 +25,45 @@ def default_scroll_duration
2525 end
2626
2727 #
28- # Scrolls the viewport so that the provided element is at the bottom. Then the viewport
29- # is further scrolled by the provided x and y offsets.
28+ # This method uses a Scroll Wheel Input to determine where and by how much to scroll
3029 #
31- # @example Scroll to element
30+ # The scroll happens from an origin plus an offset.
31+ # The amount to scroll is represented by delta_x and delta_y
32+ # The origin is either the center of a provided element or the upper left of the current viewport
33+ # The offset from the origin is represented by x and y
3234 #
35+ # @example Scroll to element
3336 # el = driver.find_element(id: "some_id")
34- # driver.action.scroll_to(el).perform
35- #
36- # @example Scroll to offset from element
37+ # driver.action.scroll(origin: element).perform
3738 #
39+ # @example Scroll from element by a specified amount
3840 # el = driver.find_element(id: "some_id")
39- # driver.action.scroll_to(el, 0, 1000).perform
40- #
41- # @param [Selenium::WebDriver::Element] element to scroll to.
42- # @param [Integer] x Optional horizontal offset to scroll from the center of the element.
43- # A negative value means scrolling left.
44- # @param [Integer] y Optional vertical offset to scroll from the center of the element.
45- # A negative value means scrolling up.
46- # @param [Symbol || String] device optional name of the WheelInput device to scroll with.
47- # @return [ActionBuilder] A self reference.
48- #
49-
50- def scroll_to ( element , x = 0 , y = 0 , device : nil )
51- scroll ( x , y , origin : ScrollOrigin . element ( element , 0 , 0 ) , device : device )
52- end
53-
54- #
55- # Scrolls the viewport from its current position by the provided offset.
56- # The origin source is the upper left corner of the viewport
57- #
58- # @example Scroll by the provided amount
59- #
60- # driver.action.scroll_by(0, 1000).perform
61- #
62- # @param [Integer] x horizontal offset. A negative value means scrolling left.
63- # @param [Integer] y vertical offset. A negative value means scrolling up.
64- # @param [Symbol || String] device Optional name of the WheelInput device to scroll with
65- # @return [ActionBuilder] A self reference.
66- #
67-
68- def scroll_by ( x = 0 , y = 0 , device : nil )
69- scroll ( x , y , origin : ScrollOrigin . viewport ( 0 , 0 ) , device : device )
70- end
71-
72- #
73- # Scrolls the viewport based on a ScrollOrigin.
74- #
75- # This method is needed instead of #scroll_to or #scroll_by
76- # when what needs to be scrolled is only in a portion of the viewport.
77- # The origin can be thought of as where on the screen you put the mouse when
78- # executing a wheel scroll, or where you put your cursor when swiping a touch pad, etc.
79- #
80- # The offset for the origin is referenced to either the upper left of the viewport or the center of the element
81- # The methods ScrollOrigin.viewport and ScrollOrigin.element are provided to ensure correct syntax
82- #
83- # @example Scroll by the provided amount originating from a source offset from upper left of the viewport
41+ # driver.action.scroll(delta_x: 100, delta_y: 200, origin: element).perform
8442 #
43+ # @example Scroll from element by a specified amount with an offset
8544 # el = driver.find_element(id: "some_id")
86- # driver.action.scroll(0, 100, ScrollOrigin.viewport(400, 200)).perform
87- #
88- # @example Scroll by the provided amount originating from a source offset from the center of the provided element
45+ # driver.action.scroll(x: 10, y: 10, delta_x: 100, delta_y: 200, origin: element).perform
8946 #
47+ # @example Scroll viewport by a specified amount
9048 # el = driver.find_element(id: "some_id")
91- # driver.action.scroll(0, 100, ScrollOrigin.element(element, x: -400, 100) ).perform
49+ # driver.action.scroll(delta_x: 100, delta_y: 200 ).perform
9250 #
93- # @see ScrollOrigin
51+ # @example Scroll viewport by a specified amount with an offset
52+ # el = driver.find_element(id: "some_id")
53+ # driver.action.scroll(x: 10, y: 10, delta_x: 100, delta_y: 200).perform
9454 #
95- # @param [Integer] x horizontal offset. A negative value means scrolling left.
96- # @param [Integer] y vertical offset. A negative value means scrolling up.
97- # @param [Hash] origin The location the scroll originates from
98- # @param [Symbol || String] device Optional name of the WheelInput device to scroll with
55+ # @option opts [Integer] x The horizontal offset from the origin from which to start the scroll.
56+ # @option opts [Integer] y The vertical offset from the origin from which to start the scroll.
57+ # @option opts [Integer] delta_x Distance along X axis to scroll using the wheel. A negative value scrolls left.
58+ # @option opts [Integer] delta_y Distance along Y axis to scroll using the wheel. A negative value scrolls up.
59+ # @option opts [String, Element] origin The origin of the scroll, either the viewport or the center of an element.
9960 # @return [ActionBuilder] A self reference.
100- # @raise [MoveTargetOutOfBoundsError] if the origin value is outside the viewport.
61+ # @raise [MoveTargetOutOfBoundsError] if the origin plus offset is located outside the viewport.
10162 #
10263
103- def scroll ( x , y , origin : ScrollOrigin . viewport ( 0 , 0 ) , device : nil )
104- wheel = wheel_input ( device )
105- opts = { delta_x : Integer ( x ) ,
106- delta_y : Integer ( y ) ,
107- duration : default_scroll_duration } . merge! ( origin )
64+ def scroll ( **opts )
65+ opts [ :duration ] = default_scroll_duration
66+ wheel = wheel_input ( opts . delete ( :device ) )
10867 wheel . create_scroll ( **opts )
10968 tick ( wheel )
11069 self
0 commit comments