3

Please help, I want to scroll down to end of the bage but it stops. the code that i try is here

browser = webdriver.Chrome()
browser.get(url)
button = browser.find_element_by_tag_name("html")
old=""
new=" "

while len(new)>len(old):
    old = browser.page_source
    button.send_keys(Keys.END)
    browser.implicitly_wait(40)
    new = browser.page_source
Vazgen
  • 51
  • 2
  • 4
  • 1
    Possible duplicate of [How can I scroll a web page using selenium webdriver in python?](https://stackoverflow.com/questions/20986631/how-can-i-scroll-a-web-page-using-selenium-webdriver-in-python) – Nouman Aug 11 '18 at 11:07

1 Answers1

6

your script for that

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

you can set no. of scrolls needed to get full length

scrolls = 4
while True:
    scrolls -= 1
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
    time.sleep(3)
    if scrolls < 0:
        break
Nihal
  • 5,262
  • 7
  • 23
  • 41