Selenium – Scroll to End of the Page

Python Selenium – Scroll to end of the page

To scroll to end of the webpage using Selenium in Python, you can use the execute_script() method to run JavaScript code that performs the scrolling action.

The syntax of the execute_script() method with the JavaScript code is given below.

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

This code scrolls down the page to the (x, y) coordinate of (0, document.body.scrollHeight), where the Y coordinate is given by the scrollable height of the webpage. Therefore, the page scrolls to the bottom left corner of the page.


In the following program, we load the URL, and scroll to the end of the page.

Python Program

from selenium import webdriver
from import Service as ChromeService
from import ChromeDriverManager
import time

# Setup chrome driver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

# Navigate to the url

# Wait for the page to load (optional)

# Scroll down using JavaScript
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

# Wait for a moment to let the page scroll (optional)

# Close the WebDriver



In this Python Selenium tutorial, we have seen how to scroll to the end of the page, with examples.

Related Tutorials

Quiz on Selenium

Q1. What is Selenium Python used for?

Not answered

Q2. Which of the following is not a popular web driver used in Selenium Python?

Not answered

Q3. Which of the following is not a method to wait for a web element to load in Selenium Python?

Not answered

Q4. What is the method used to take a screenshot in Selenium Python?

Not answered

Q5. Which of the following is not a commonly used web element locator in Selenium Python?

Not answered
Code copied to clipboard successfully 👍