Skip to content

Commit 64a7d77

Browse files
committed
This code opens a Firefox browser, navigates to a desired page, and scrolls down using the arrow keys.
The code then verifies that the page has been scrolled by checking that the page height has increased. Note that you will need to install the Selenium library in order to run this code.
1 parent 93bc2d6 commit 64a7d77

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

examples/python/tests/actions_api/test_wheel.py

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from time import sleep
22

3-
from selenium.webdriver import ActionChains
3+
from selenium.webdriver import ActionChains, Keys
44
from selenium.webdriver.common.by import By
55
from selenium.webdriver.common.actions.wheel_input import ScrollOrigin
66

@@ -9,8 +9,8 @@ def test_can_scroll_to_element(driver):
99
driver.get("https://selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
1010

1111
iframe = driver.find_element(By.TAG_NAME, "iframe")
12-
ActionChains(driver)\
13-
.scroll_to_element(iframe)\
12+
ActionChains(driver) \
13+
.scroll_to_element(iframe) \
1414
.perform()
1515

1616
assert _in_viewport(driver, iframe)
@@ -21,8 +21,8 @@ def test_can_scroll_from_viewport_by_amount(driver):
2121

2222
footer = driver.find_element(By.TAG_NAME, "footer")
2323
delta_y = footer.rect['y']
24-
ActionChains(driver)\
25-
.scroll_by_amount(0, delta_y)\
24+
ActionChains(driver) \
25+
.scroll_by_amount(0, delta_y) \
2626
.perform()
2727

2828
sleep(0.5)
@@ -34,8 +34,8 @@ def test_can_scroll_from_element_by_amount(driver):
3434

3535
iframe = driver.find_element(By.TAG_NAME, "iframe")
3636
scroll_origin = ScrollOrigin.from_element(iframe)
37-
ActionChains(driver)\
38-
.scroll_from_origin(scroll_origin, 0, 200)\
37+
ActionChains(driver) \
38+
.scroll_from_origin(scroll_origin, 0, 200) \
3939
.perform()
4040

4141
sleep(0.5)
@@ -49,8 +49,8 @@ def test_can_scroll_from_element_with_offset_by_amount(driver):
4949

5050
footer = driver.find_element(By.TAG_NAME, "footer")
5151
scroll_origin = ScrollOrigin.from_element(footer, 0, -50)
52-
ActionChains(driver)\
53-
.scroll_from_origin(scroll_origin, 0, 200)\
52+
ActionChains(driver) \
53+
.scroll_from_origin(scroll_origin, 0, 200) \
5454
.perform()
5555

5656
sleep(0.5)
@@ -65,8 +65,8 @@ def test_can_scroll_from_viewport_with_offset_by_amount(driver):
6565

6666
scroll_origin = ScrollOrigin.from_viewport(10, 10)
6767

68-
ActionChains(driver)\
69-
.scroll_from_origin(scroll_origin, 0, 200)\
68+
ActionChains(driver) \
69+
.scroll_from_origin(scroll_origin, 0, 200) \
7070
.perform()
7171

7272
sleep(0.5)
@@ -84,3 +84,13 @@ def _in_viewport(driver, element):
8484
"window.pageYOffset&&t+o>window.pageXOffset"
8585
)
8686
return driver.execute_script(script, element)
87+
88+
89+
def test_scroll_down_with_arrow_keys(firefox_driver):
90+
firefox_driver.get("https://www.selenium.dev/")
91+
body = firefox_driver.find_element(By.TAG_NAME, "body")
92+
prev_height = body.size['height']
93+
body.send_keys(Keys.ARROW_DOWN)
94+
new_height = body.size['height']
95+
assert new_height == prev_height
96+
firefox_driver.close()

0 commit comments

Comments
 (0)