1818"""Tests for advanced user interactions."""
1919import pytest
2020from selenium .common .exceptions import MoveTargetOutOfBoundsException
21+ from selenium .webdriver .common .actions .wheel_input import ScrollOrigin
2122
2223from selenium .webdriver .common .by import By
2324from selenium .webdriver .common .keys import Keys
@@ -269,7 +270,7 @@ def test_can_scroll_to_element(driver, pages):
269270
270271 assert not _in_viewport (driver , iframe )
271272
272- ActionChains (driver ).scroll ( 0 , 0 , 0 , 0 , origin = iframe ).perform ()
273+ ActionChains (driver ).scroll_to_element ( iframe ).perform ()
273274
274275 assert _in_viewport (driver , iframe )
275276
@@ -279,8 +280,9 @@ def test_can_scroll_to_element(driver, pages):
279280def test_can_scroll_from_element_by_amount (driver , pages ):
280281 pages .load ("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html" )
281282 iframe = driver .find_element (By .TAG_NAME , "iframe" )
283+ scroll_origin = ScrollOrigin .from_element (iframe )
282284
283- ActionChains (driver ).scroll ( 0 , 0 , 0 , 200 , origin = iframe ).pause (0.2 ).perform ()
285+ ActionChains (driver ).scroll_from_origin ( scroll_origin , 0 , 200 ).pause (0.2 ).perform ()
284286
285287 driver .switch_to .frame (iframe )
286288 checkbox = driver .find_element (By .NAME , "scroll_checkbox" )
@@ -292,8 +294,9 @@ def test_can_scroll_from_element_by_amount(driver, pages):
292294def test_can_scroll_from_element_with_offset_by_amount (driver , pages ):
293295 pages .load ("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html" )
294296 footer = driver .find_element (By .TAG_NAME , "footer" )
297+ scroll_origin = ScrollOrigin .from_element (footer , 0 , - 50 )
295298
296- ActionChains (driver ).scroll ( 0 , - 50 , 0 , 200 , origin = footer ).pause (0.2 ).perform ()
299+ ActionChains (driver ).scroll_from_origin ( scroll_origin , 0 , 200 ).pause (0.2 ).perform ()
297300
298301 iframe = driver .find_element (By .TAG_NAME , "iframe" )
299302 driver .switch_to .frame (iframe )
@@ -306,9 +309,10 @@ def test_can_scroll_from_element_with_offset_by_amount(driver, pages):
306309def test_errors_when_element_offset_not_in_viewport (driver , pages ):
307310 pages .load ("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html" )
308311 footer = driver .find_element (By .TAG_NAME , "footer" )
312+ scroll_origin = ScrollOrigin .from_element (footer , 0 , 50 )
309313
310314 with pytest .raises (MoveTargetOutOfBoundsException ):
311- ActionChains (driver ).scroll ( 0 , 50 , 0 , 200 , origin = footer ).perform ()
315+ ActionChains (driver ).scroll_from_origin ( scroll_origin , 0 , 200 ). pause ( 0.2 ).perform ()
312316
313317
314318@pytest .mark .xfail_firefox
@@ -318,7 +322,7 @@ def test_can_scroll_from_viewport_by_amount(driver, pages):
318322 footer = driver .find_element (By .TAG_NAME , "footer" )
319323 delta_y = footer .rect ['y' ]
320324
321- ActionChains (driver ).scroll ( 0 , 0 , 0 , delta_y ).pause (0.2 ).perform ()
325+ ActionChains (driver ).scroll_by_amount ( 0 , delta_y ).pause (0.2 ).perform ()
322326
323327 assert _in_viewport (driver , footer )
324328
@@ -327,8 +331,9 @@ def test_can_scroll_from_viewport_by_amount(driver, pages):
327331@pytest .mark .xfail_remote
328332def test_can_scroll_from_viewport_with_offset_by_amount (driver , pages ):
329333 pages .load ("scrolling_tests/frame_with_nested_scrolling_frame.html" )
334+ scroll_origin = ScrollOrigin .from_viewport (10 , 10 )
330335
331- ActionChains (driver ).scroll ( 10 , 10 , 0 , 200 ).pause (0.2 ).perform ()
336+ ActionChains (driver ).scroll_from_origin ( scroll_origin , 0 , 200 ).pause (0.2 ).perform ()
332337
333338 iframe = driver .find_element (By .TAG_NAME , "iframe" )
334339 driver .switch_to .frame (iframe )
@@ -340,9 +345,10 @@ def test_can_scroll_from_viewport_with_offset_by_amount(driver, pages):
340345@pytest .mark .xfail_remote
341346def test_errors_when_origin_offset_not_in_viewport (driver , pages ):
342347 pages .load ("scrolling_tests/frame_with_nested_scrolling_frame.html" )
348+ scroll_origin = ScrollOrigin .from_viewport (- 10 , - 10 )
343349
344350 with pytest .raises (MoveTargetOutOfBoundsException ):
345- ActionChains (driver ).scroll ( - 10 , - 10 , 0 , 200 ).perform ()
351+ ActionChains (driver ).scroll_from_origin ( scroll_origin , 0 , 200 ). pause ( 0.2 ).perform ()
346352
347353
348354def _get_events (driver ):
0 commit comments