Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

+1 vote
I'm actually using WebDriver to parse through page displaying all names of friends on facebook, and i'm extracting all their ids from the AJAX script. But I'm unable to scroll down to get more friends. How to scroll down using Selenium code? I'm using Python.
May 21, 2018 in Selenium by eLiJha
• 760 points

2 answers to this question.

0 votes can. This is how its done.

driver.execute_script("window.scrollTo(0, Y)") 

where Y is the height (on a fullhd monitor it's 1080).

Or, you can also use this to scroll down to the bottom of the page.

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
answered May 21, 2018 by sniffy_god
• 780 points
Not Working Tell me another command

Hi Shyamal, can you please state what exactly is causing the problem with above command or what is the error you are facing. You can use this line of code also:

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

0 votes
I using next code for facebook for group scraping:

        # Pause time after scrool

        # Get page height
        last_height = browser.script(query="return document.body.scrollHeight")

        while True:
            # Make scroll down to bottom
            browser.script(query="window.scrollTo(0, document.body.scrollHeight);")

            # Wait to load page
            # Calculate new scroll height and compare with last scroll height
            new_height = browser.script(query="return document.body.scrollHeight")
            # break by end of results tag (<div class="phm _64f">End of Results</div>)
                browser.find(method="xpath", query="//div[@class='phm _64f'][contains(.,'End of Results')]", error=0)
            except NoSuchElementException:
            # break by size
            if new_height == last_height:
            last_height = new_height
answered May 16, 2019 by

Hi @Mslavikas, can you suggest any shorter way of doing like this:

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

 As this single line of code can be used to scroll a page down.

Your suggestions are welcomed.

Related Questions In Selenium

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
0 votes
2 answers

When executing my Jenkins tests with Selenium WebDriver, I do not see a GUI.

Hi eLiJha, I also faced the same issue ...READ MORE

answered Jul 15, 2019 in Selenium by nayan
• 160 points
+2 votes
1 answer

I want the console.log output from Chrome. I'm working with selenium on Python

So this is how you do it ...READ MORE

answered May 3, 2018 in Selenium by sniffy_god
• 780 points