Skip to content

Scroll down to end of page in Selenium Python

Advertisements
SCROLL_PAUSE_TIME = 0.3

# Get scroll height of the page
last_height = driver.execute_script("return document.body.scrollHeight")

while True:
    # Scroll down to bottom of the page
    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 scrolled height
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.