File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 22
33### Added
44
5- ` Ferrum::Network::Request#headers ` are enhanced and supplemented with ` Network.requestWillBeSentExtraInfo ` [ #506 ]
6- ` Ferrum::Page#off ` to unsubscribe from CDP events [ #455 ]
5+ - ` Ferrum::Network::Request#headers ` are enhanced and supplemented with ` Network.requestWillBeSentExtraInfo ` [ #506 ]
6+ - ` Ferrum::Page#off ` to unsubscribe from CDP events [ #455 ]
7+ - ` Ferrum::Mouse#scroll_by ` to be able to scroll by, as alternative to ` scroll_to ` [ #514 ]
78
89### Changed
910
Original file line number Diff line number Diff line change @@ -18,6 +18,23 @@ def initialize(page)
1818 @buttons = 0
1919 end
2020
21+ #
22+ # Scroll page by the given amount x, y.
23+ #
24+ # @param [Integer] x
25+ # The horizontal pixel value that you want to scroll by.
26+ #
27+ # @param [Integer] y
28+ # The vertical pixel value that you want to scroll by.
29+ #
30+ # @example
31+ # browser.go_to("https://www.google.com/search?q=Ruby+headless+driver+for+Capybara")
32+ # browser.mouse.scroll_by(0, 400)
33+ #
34+ def scroll_by ( x , y )
35+ tap { @page . execute ( "window.scrollBy(#{ x } , #{ y } )" ) }
36+ end
37+
2138 #
2239 # Scroll page to a given x, y coordinates.
2340 #
Original file line number Diff line number Diff line change 3232 end
3333 end
3434
35+ describe "#scroll_by" do
36+ it "allows the page to be scrolled" do
37+ browser . go_to ( "/ferrum/long_page" )
38+ browser . resize ( width : 10 , height : 10 )
39+ browser . mouse . scroll_by ( 30 , 70 )
40+ browser . mouse . scroll_by ( 40 , -50 )
41+ browser . mouse . scroll_by ( -60 , 0 )
42+ expect (
43+ browser . evaluate ( "[window.scrollX, window.scrollY]" )
44+ ) . to eq ( [ 10 , 20 ] )
45+ end
46+ end
47+
3548 describe "#scroll_to" do
3649 it "allows the page to be scrolled" do
3750 browser . go_to ( "/ferrum/long_page" )
You can’t perform that action at this time.
0 commit comments