18
18
"""Tests for advanced user interactions."""
19
19
import pytest
20
20
from selenium .common .exceptions import MoveTargetOutOfBoundsException
21
+ from selenium .webdriver .common .actions .wheel_input import ScrollOrigin
21
22
22
23
from selenium .webdriver .common .by import By
23
24
from selenium .webdriver .common .keys import Keys
@@ -269,7 +270,7 @@ def test_can_scroll_to_element(driver, pages):
269
270
270
271
assert not _in_viewport (driver , iframe )
271
272
272
- ActionChains (driver ).scroll ( 0 , 0 , 0 , 0 , origin = iframe ).perform ()
273
+ ActionChains (driver ).scroll_to_element ( iframe ).perform ()
273
274
274
275
assert _in_viewport (driver , iframe )
275
276
@@ -279,8 +280,9 @@ def test_can_scroll_to_element(driver, pages):
279
280
def test_can_scroll_from_element_by_amount (driver , pages ):
280
281
pages .load ("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html" )
281
282
iframe = driver .find_element (By .TAG_NAME , "iframe" )
283
+ scroll_origin = ScrollOrigin .from_element (iframe )
282
284
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 ()
284
286
285
287
driver .switch_to .frame (iframe )
286
288
checkbox = driver .find_element (By .NAME , "scroll_checkbox" )
@@ -292,8 +294,9 @@ def test_can_scroll_from_element_by_amount(driver, pages):
292
294
def test_can_scroll_from_element_with_offset_by_amount (driver , pages ):
293
295
pages .load ("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html" )
294
296
footer = driver .find_element (By .TAG_NAME , "footer" )
297
+ scroll_origin = ScrollOrigin .from_element (footer , 0 , - 50 )
295
298
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 ()
297
300
298
301
iframe = driver .find_element (By .TAG_NAME , "iframe" )
299
302
driver .switch_to .frame (iframe )
@@ -306,9 +309,10 @@ def test_can_scroll_from_element_with_offset_by_amount(driver, pages):
306
309
def test_errors_when_element_offset_not_in_viewport (driver , pages ):
307
310
pages .load ("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html" )
308
311
footer = driver .find_element (By .TAG_NAME , "footer" )
312
+ scroll_origin = ScrollOrigin .from_element (footer , 0 , 50 )
309
313
310
314
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 ()
312
316
313
317
314
318
@pytest .mark .xfail_firefox
@@ -318,7 +322,7 @@ def test_can_scroll_from_viewport_by_amount(driver, pages):
318
322
footer = driver .find_element (By .TAG_NAME , "footer" )
319
323
delta_y = footer .rect ['y' ]
320
324
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 ()
322
326
323
327
assert _in_viewport (driver , footer )
324
328
@@ -327,8 +331,9 @@ def test_can_scroll_from_viewport_by_amount(driver, pages):
327
331
@pytest .mark .xfail_remote
328
332
def test_can_scroll_from_viewport_with_offset_by_amount (driver , pages ):
329
333
pages .load ("scrolling_tests/frame_with_nested_scrolling_frame.html" )
334
+ scroll_origin = ScrollOrigin .from_viewport (10 , 10 )
330
335
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 ()
332
337
333
338
iframe = driver .find_element (By .TAG_NAME , "iframe" )
334
339
driver .switch_to .frame (iframe )
@@ -340,9 +345,10 @@ def test_can_scroll_from_viewport_with_offset_by_amount(driver, pages):
340
345
@pytest .mark .xfail_remote
341
346
def test_errors_when_origin_offset_not_in_viewport (driver , pages ):
342
347
pages .load ("scrolling_tests/frame_with_nested_scrolling_frame.html" )
348
+ scroll_origin = ScrollOrigin .from_viewport (- 10 , - 10 )
343
349
344
350
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 ()
346
352
347
353
348
354
def _get_events (driver ):
0 commit comments