Maria
Maria

Reputation: 33

Scroll down Followers/Following List in the Instagram Box

Hi :) I was looking for a solution to scroll down the following/followers list in the Instagram Box. The step I do are the following:

Once the followers list is shown up, when I scroll down using the line:

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

I get that the page below the box scrolls down :(

How can scroll down the list in the followers box?

Thanks in advance :) Maria.

Upvotes: 2

Views: 4632

Answers (3)

Roni
Roni

Reputation: 1

You can test the following method. I tested and it works.

    """Scroll a specific element one or more times with small delay between
    them."""

    while times > 0:
        self.driver.execute_script(
            'arguments[0].scrollTop = arguments[0].scrollHeight',
            element
        )
        time.sleep(.2)
        times -= 1

Upvotes: 0

Daniel
Daniel

Reputation: 5

This method works perfectly for my situation. Don't change the sleep times within the loop please. They allow reload of followers/following within the dialogue box without having to scroll back up.

    FList = driver.find_element_by_css_selector('div[role=\'dialog\'] ul')
numberOfFollowersInList = len(FList.find_elements_by_css_selector('li'))

FList.click()
actionChain = webdriver.ActionChains(driver)
time.sleep(random.randint(2,4))

while (numberOfFollowersInList < max):
    actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()        
    numberOfFollowersInList = len(FList.find_elements_by_css_selector('li'))
    time.sleep(0.4)
    print(numberOfFollowersInList)
    actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()            
    time.sleep(1)

Upvotes: 0

ewwink
ewwink

Reputation: 19154

you can try execute_script() and change .isgrP if different class

...
from selenium.webdriver.support.ui import WebDriverWait 
.....
# after click follower link, wait until dialog appear
WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector('div[role="dialog"]'))
# now scroll
driver.execute_script('''
    var fDialog = document.querySelector('div[role="dialog"] .isgrP');
    fDialog.scrollTop = fDialog.scrollHeight
''')

Upvotes: 3

Related Questions