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

0 votes
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
• 700 points
4,222 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 760 points
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 6 days ago 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
1 answer
+1 vote
2 answers

How to scroll down a webpage in selenium using Java?

This works... JavascriptExecutor jse = (JavascriptExecutor)driver; j ...READ MORE

answered Apr 3 in Selenium by anonymous
366 views
0 votes
1 answer

How to scroll the Page up or down in Selenium WebDriver? (using java)

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
4,349 views
0 votes
1 answer
0 votes
1 answer

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,030 points
60 views
0 votes
1 answer
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,130 points
426 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
46 views
0 votes
1 answer
+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
• 760 points
5,239 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.