     [Answers](https://scrapfly.io/blog)   /  [python](https://scrapfly.io/blog/tag/python)   /  [How to scroll to an element in Selenium?](https://scrapfly.io/blog/answers/scroll-to-element-selenium)   # How to scroll to an element in Selenium?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Nov 25, 2022 2 min read [\#python](https://scrapfly.io/blog/tag/python) [\#selenium](https://scrapfly.io/blog/tag/selenium) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fscroll-to-element-selenium "Share on LinkedIn")    

 

 

The Selenium headless browser automation library enables full web automation control, and one of these automation tasks is scrolls. In this guide, we'll explain using Python selenium scroll to element. Let's get started!



## Installation

Let's start with the installation process. We'll be using the below packages:

- [Selenium](https://pypi.org/project/selenium/): The Selenium Python client to communicate with the web driver API.
- [webdriver-manager](https://pypi.org/project/webdriver-manager/): To automatically download the Selenium web driver binaries itself The above packages can be installed using the below `pip` command:shell```shell
    pip install selenium webdriver-manager
    ```

Next, use the `webdriver-amanger` to automatically download the Selenium web driver:

python```python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
```



The above script will install the Chrome browser driver. However, other browsers are supported. See the [official documentation](https://github.com/SergeyPirogov/webdriver_manager) for the available engines.



## Using scrollIntoView

To scroll into a specific element using Sleneium, we can follow the below steps:

- Select a particular element to scroll into using its equivalent CSS or XPath selector
- Use the `scrollIntoView` method with the selected HTML element

Let's apply the above steps within our Python Selenium code:

python```python
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

driver.get("https://web-scraping.dev/product/1")

# scroll to an element at the bottom of the page
element = driver.find_element(By.CSS_SELECTOR, 'footer')

# execute scrollIntoView script with our element as the argument:
driver.execute_script(
    "arguments[0].scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'end' });", 
    element
)

time.sleep(5) # observe the new view
driver.close() # close the browser
```



Above, we start by selecting a web element at the bottom of them page using CSS selectors. Then, we use the `execute_script` method to execute JavaScript code to scroll to the element the `scrollIntoView` function. We also specify block and inline arguments to `end` value to scroll to the bottom of the horizontal right of the element - this ensures highest visibility of the element. For more see [browser's scrollIntoView documentation](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView).

For further scrolling techniques, refer to our guide on [scrolling with selenium](https://scrapfly.io/blog/answers/how-to-scroll-to-the-bottom-with-selenium).



 

    Table of Contents- [Installation](#installation)
- [Using scrollIntoView](#using-scrollintoview)
 
    Join the Newsletter  Get monthly web scraping insights 

 

  



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fscroll-to-element-selenium) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fscroll-to-element-selenium) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fscroll-to-element-selenium) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fscroll-to-element-selenium) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fscroll-to-element-selenium) 



 ## Related Articles

 [  

 python headless-browser 

### Web Scraping with Selenium and Python

Introduction to web scraping dynamic javascript powered websites and web apps using Selenium browser automation library ...

 

 ](https://scrapfly.io/blog/posts/web-scraping-with-selenium-and-python) [  

 python headless-browser 

### How To Take Screenshots In Python?

Learn how to take Python screenshots through Selenium and Playwright, including common browser tips and tricks for custo...

 

 ](https://scrapfly.io/blog/posts/how-to-take-screenshots-in-python) [  

 http nodejs 

### Web Scraping With NodeJS and Javascript

In this article we'll take a look at scraping using Javascript through NodeJS. We'll cover common web scraping libraries...

 

 ](https://scrapfly.io/blog/posts/web-scraping-with-nodejs) 

  ## Related Questions

- [ Q How to scroll to the bottom of the page with Selenium? ](https://scrapfly.io/blog/answers/how-to-scroll-to-the-bottom-with-selenium)
- [ Q How to take a screenshot with Selenium? ](https://scrapfly.io/blog/answers/how-to-take-screenshot-with-selenium)
- [ Q How to find elements without a specific attribute in BeautifulSoup? ](https://scrapfly.io/blog/answers/how-to-find-elements-without-attribute-in-beautifulsoup)
- [ Q How to select elements of a specific position in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-of-specific-position-in-xpath)
 
  



   



 Run headless browsers at scale, **1,000 free credits** [Start Free](https://scrapfly.io/register)