how to scroll down to end of page in selenium python

Solutions on MaxInterview for how to scroll down to end of page in selenium python by the best coders in the world

showing results for - "how to scroll down to end of page in selenium python"
Antoine
24 Oct 2017
1SCROLL_PAUSE_TIME = 0.5
2
3# Get scroll height
4last_height = driver.execute_script("return document.body.scrollHeight")
5
6while True:
7    # Scroll down to bottom
8    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
9
10    # Wait to load page
11    time.sleep(SCROLL_PAUSE_TIME)
12
13    # Calculate new scroll height and compare with last scroll height
14    new_height = driver.execute_script("return document.body.scrollHeight")
15    if new_height == last_height:
16        break
17    last_height = new_height
18