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
• 770 points
26,072 views

2 answers to this question.

0 votes

Yup..you 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
        SCROLL_PAUSE_TIME = 2

        # 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
            time.sleep(SCROLL_PAUSE_TIME)
            # 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>)
            try:
                browser.find(method="xpath", query="//div[@class='phm _64f'][contains(.,'End of Results')]", error=0)
            except NoSuchElementException:
                pass
            else:
                break
            # break by size
            if new_height == last_height:
                break
            last_height = new_height
answered May 16, 2019 by mslavikas@gmail.com

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,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
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,910 points
7,221 views
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 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
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
13,374 views
+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
41,832 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP