I am trying to scroll down a page using selenium with python and using the execute_script
command. However, when I execute my code, I don't scroll down the bottom of my page. Following is my code:
def create_browser(first_page=None):
print "Starting"
browser = webdriver.Firefox()
if first_page:
browser.get(first_page)
print "Done."
return browser
browser = create_browser()
print 'loaded'
browser.get('https://chrome.google.com/webstore/detail/ie-tab/hehijbfgiekmjfkfjpbkbammjbdenadd/reviews')
time.sleep(4)
elem = WebDriverWait(browser, 30).until(EC.presence_of_all_elements_located((By.XPATH, '//a[@ga:type="NextLink"]')))
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
print "Scrolled."
I get the "Scrolled." printed on my console but the page isn't scrolled down. I have read some pages saying that browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
will scroll me to the bottom of my page. However, this doesn't happen in my case. Does this happen to do with the web page using AJAX? Or is it something different? More importantly, how do I scroll down the page? I want to scroll down the page and click on "Next" so that I can see the next reviews and I want to keep doing that until the reviews end. How do I do that?