How to scroll to specific element in Selenium Python?

Python Selenium – Scroll to element

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

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

driver.execute_script("arguments[0].scrollIntoView();", element)

This code scrolls down the page to the starting of the element.


In the following program, we load the URL, and scroll to the element with id=”para3″.

Python Program

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

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

# Navigate to the url

# Get the element
the_element = driver.find_element(By.ID, "para3")


# Scroll to the element using JavaScript
driver.execute_script("arguments[0].scrollIntoView();", the_element)


# Close the driver

We have introduced some time delay before and after the scrolling action.


In this Python Selenium tutorial, we have seen how to scroll to a specific element in the web page, with examples.

Related Tutorials

Quiz on Selenium

Q1. What is Selenium Python used for?

Not answered

Q2. What is a web driver 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. What is the method used to clear the text from an input field in Selenium Python?

Not answered
Code copied to clipboard successfully 👍