How to scroll to the end of the page using selenium in Python?

selenium scroll down python
python selenium mouse scroll
how to scroll using selenium in python
selenium scroll to element python
infinite scroll selenium python
selenium scroll to bottom
how to scroll table in selenium webdriver + python
how to scroll a div in selenium webdriver python.

I am trying to scroll to the end of a page so that I can make all the data visible and extract it. I tried to find a command for it but it's available in java (driver.executeScript) but couldn't find for python. Right now I am making the computer press the end key thousand times:

while i<1000:
    scroll = driver.find_element_by_tag_name('body').send_keys(Keys.END)
    i+=1

And I also tried driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") but it scrolls to the end of the loaded page and the same thing END key does. Once at the bottom of the page, next content loads. But now it doesn't scroll again.

I know there will be a very nice alternative for this.

How do I scroll to the end of the page using selenium in Python?


Well I finally figured out a solution:

lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
    match=False
        while(match==False):
                lastCount = lenOfPage
                time.sleep(3)
                lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
                if lastCount==lenOfPage:
                    match=True

How to scroll to the end of the page using selenium in Python , from selenium import webdriver. class fblogin(unittest.TestCase): driver.​implicitly_wait( 30 ). #using the JavaScriptExecutor to scroll down to bottom of window. Selenium Scroll Down Webpage 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.


This can be done in one line by scrolling to document.body.scrollHeight

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

Scrolling Down a Page – All Things Selenium and QA, Example#. 1. Scrolling to target element ("BROWSE TEMPLATES" button at the bottom of page) with Actions from selenium import webdriver from  Scroll in Selenium. To scroll using Selenium, you can use JavaScriptExecutor interface that helps to execute JavaScript methods through Selenium Webdriver . Learn more about JavaScriptExecutor . Syntax : JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript(Script,Arguments); Script – This is the JavaScript that needs to execute.


None of these were working for me, but the below solution did:

driver.get("https://www.youtube.com/user/teachingmensfashion/videos")


def scroll_to_bottom(driver):

    old_position = 0
    new_position = None

    while new_position != old_position:
        # Get old scroll position
        old_position = driver.execute_script(
                ("return (window.pageYOffset !== undefined) ?"
                 " window.pageYOffset : (document.documentElement ||"
                 " document.body.parentNode || document.body);"))
        # Sleep and Scroll
        time.sleep(1)
        driver.execute_script((
                "var scrollingElement = (document.scrollingElement ||"
                " document.body);scrollingElement.scrollTop ="
                " scrollingElement.scrollHeight;"))
        # Get new position
        new_position = driver.execute_script(
                ("return (window.pageYOffset !== undefined) ?"
                 " window.pageYOffset : (document.documentElement ||"
                 " document.body.parentNode || document.body);"))

scroll_to_bottom(driver)

selenium-webdriver - Scrolling using Python, Or, you can also use this to scroll down to the bottom of the page. driver.​execute_script("window.scrollTo(0, document.body.scrollHeight);"). I need to scroll down page till end in the Selenium WebDriver. I tried to scroll down the page by using the following code snippet: JavascriptExecutor jse6 = (JavascriptExecutor) driver; jse6.executeScript("window.scrollBy(0,250)", ""); It's being scrolled but I need to scroll down till end page.


You can utilize scrollingElement with scrollTop and scrollHeight to to scroll to the end of a page.

driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")

References :

  1. Scroll Automatically to the Bottom of the Page
  2. Document.scrollingElement - Web APIs | MDN
  3. Element.scrollHeight - Web APIs | MDN
  4. Element.scrollTop - Web APIs | MDN

Is it possible to scroll down in a webpage using selenium webdriver , You can also use. driver.execute_script("window.scrollTo(0, document.body.​scrollHeight);"). to scroll to the bottom of the page. If you want to  Scrolling is an essential feature for using any web page on the internet. It doesn’t matter what content a web page hosts, it is almost never possible to place all content on the first fold and do away with the scroll bars, both horizontal and vertical.


How can I scroll a web page using selenium webdriver in python , I am trying to use Selenium with python to simulate dynamically loading a web '​scroll down to the bottom of a page and loading', combined a for loop without a  You can use send_keys to simulate an END (or PAGE_DOWN) key press (which normally scroll the page): from selenium.webdriver.common.keys import Keys html = driver.find_element_by_tag_name('html') html.send_keys(Keys.END)


[Python] how to scroll down the end of web page when it is a , Scenario 2: To scroll down the web page by the visibility of the element. Scenario 3: To scroll down the web page at the bottom of the page. The element ‘li’ have a parent element by id ‘ui-id-2’, which is active when we click another element with id ‘seller_email’. Presently when element ‘ui-id-2’ is active but the child ‘li’ is not visible in the view. Lets see, how we can perform a scroll action to the parent element.


How to Scroll Down or UP a Page in Selenium Webdriver, Learn to scroll to bottom and scroll to view with javascript executor. iOS application Duration: 4:20 Posted: Sep 7, 2018 For a site where the entire page has infinite scroll, you can use the following code to scroll to the “true” bottom and then grab the content: import time from selenium import webdriver from bs4 import BeautifulSoup as bs # I used Firefox; you can use whichever browser you like. browser = webdriver .