Do you want the Web Browser to scroll to the end of the page while using Python Selenium?
You can do that with code, the trick is to inject Javascript code to be webpage. After you load a webpage, scroll down the page by injecting javascript.You can scroll down a specific amount or all the way to the bottom.
Related course:
Scroll down webpage
Example
Before you start make sure the Selenium Web Driver is installed and that you have the selenium module installed. The web driver must be the appropriate web driver for the browser (same version). For Firefox that’s the geckoDriver, for Chrome that’s the ChromeDriver. The version of the driver must be intended for the browser version, an outdated version most likely wont work.
The selenium scroll down code is shown below. It cals the method execute_script()
with the javascript to scroll to the end of the web page.
1 | #_*_coding: utf-8_*_ |
First the required modules are loaded. You’ll need the selenium module and the time module.
1 | #_*_coding: utf-8_*_ |
Then initialize the web browser. This can be Firefox or another supported browser (Chrome, Edge, Safari)
1 | browser=webdriver.Firefox() |
Get your webpage wit the get() method, which has a parameter the URL to load.
1 | browser.get("https://en.wikipedia.org") |
And finally scroll down the complete body height or a specific height.
1 | browser.execute_script("window.scrollTo(0,document.body.scrollHeight)") |
If you are new to selenium, then I highly recommend this book.