Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Elmasekar/Python-selenium-scroll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

How to scroll webpage in automation test in Python-selenium on LambdaTest

If you want to test scrolling of a webpage using an automation test in Python-selenium on LambdaTest, you can use the follwing steps. You can refer to sample test repo here.

Steps

Scrolling to bottom of the page

To scroll to the bottom of the page, you can use the following line of code (refer to scroll.py for full code):

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

Infitinite scroll

If you want to scroll to a page with infinite loading, like social network ones, facebook etc. You can use the following code (refer to lambdatest.py for full code):

SCROLL_PAUSE_TIME = 0.5
# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
#controls how many times scrolled to bottom
scroll_pass = 0
#change to True for infinite scroll
while scroll_pass < 10:
 # Scroll down to bottom
 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
 # Wait to load page
 time.sleep(SCROLL_PAUSE_TIME)
 # Calculate new scroll height and compare with last scroll height
 new_height = driver.execute_script("return document.body.scrollHeight")
 if new_height == last_height:
 break
 last_height = new_height 
 scroll_passs+=1

Run your test

python lambdatest.py

Links:

LambdaTest Community

AltStyle によって変換されたページ (->オリジナル) /