0

On Quora, i want to scroll to the bottom of the window i am getting when clicking on view upvoters button, in order to get all upvoters names, the code for scrolling down a standard browser window does not seem to work with an overlay window, any suggestion? Here is my code for scrolldown function and for clicking on 'View upvoters' Button:

def scrolldown(browser):

    src_updated = browser.page_source
    src = ""
    while  src != src_updated:
        src = src_updated
        time.sleep(5)
        browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(5)
        src_updated = browser.page_source      
    #if (DEBUG): print ("window maximized...")
    return browser

browser.get('https://www.quora.com/What-is-it-like-to-regret-having-children')
for p in browser.find_elements_by_class_name('AnswerVoterListModalLink'):
        time.sleep(5)

        p.click()
        time.sleep(5)
        browser=scrolldown(browser)
        time.sleep(5)
        c=0
        for div in upvoter_name :#browser.find_elements_by_class_name('author_info'):
           list_of_upvoters.append(div.find_element_by_class_name('user').text)
           c+=1
        print("number of upvoters for this answer is :" + str(c))
Youcef
  • 1,103
  • 2
  • 11
  • 26

1 Answers1

0

I think you can scroll down to the very last element by using something like in this answer. According to the answer, you can scroll down to the last element with something like this:

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_xpath("//div[@class='pagedlist_item'][last()]")

actions = ActionChains(driver)
actions.move_to_element(element).perform()
Guven Degirmenci
  • 684
  • 7
  • 16