• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Scroll Down Using Selenium in Python

Scroll Down Using Selenium in Python

May 20, 2022 Leave a Comment

To scroll down using Selenium in Python, you can use the Selenium webdriver execute_script() function which executes JavaScript code in the browser.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("http://theprogrammingexpert.com/")

#Scroll to Bottom of Webpage
driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")

The Selenium Python module gives you the tools you need to be able to automate many tasks when working with web browser.

When working with web browsers, it’s possible you may want to scroll down to the bottom of a webpage or scroll down to a particular pixel height.

To scroll down using Selenium in your Python code, you can use the Selenium webdriver execute_script() function. execute_script() is a versatile function and allows you to execute JavaScript code in the browser.

With JavaScript, we can easily scroll down in a browser.

How to Scroll Down to Bottom of Webpage Using Selenium

To scroll down to the bottom of a webpage using Selenium, you can use the execute_script() function to execute the JavaScript function window.scrollTo() and pass ‘document.body.scrollHeight’ for the second parameter.

Below shows you a simple example of how you can use Selenium to scroll down to the bottom of a webpage.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("http://theprogrammingexpert.com/")

#Scroll to Bottom of Webpage
driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")

How to Scroll Down to Specific Height Using Selenium

If you want to scroll down to a specific pixel height, then you can change the second parameter of the window.scrollTo() function.

For example, if you want to scroll down to pixel 600, then pass ‘600’ to window.scrollTo().

Below shows you how to use Selenium to scroll down to a specific height in your Python code.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("http://theprogrammingexpert.com/")

#Scroll to Pixel 600 of Webpage
driver.execute_script("window.scrollTo(0,600))

Hopefully this article has been useful for you to learn how to scroll down using Selenium in Python.

Other Articles You'll Also Like:

  • 1.  Using Selenium to Get Text from Element in Python
  • 2.  Initialize Multiple Variables in Python
  • 3.  Get Days in Month Using Python
  • 4.  Python rjust Function – Right Justify String Variable
  • 5.  Get pandas Series First Element in Python
  • 6.  Return Multiple Values from Function in Python
  • 7.  pandas percentile – Calculate Percentiles of Series or Columns in DataFrame
  • 8.  Using Python to Convert Float to Int
  • 9.  Read Last N Lines of File in Python
  • 10.  pandas variance – Compute Variance of Variables in DataFrame

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy