How to scroll a page to the end How to scroll a page to the end selenium selenium

How to scroll a page to the end


You need something to rely on, some indicator for you to stop scrolling. Here is an example use case when we would stop scrolling if more than N particular elements are already loaded:

Similar use case:

FYI, you may have noticed an other way to scroll to bottom - scrolling into view of a footer:

footer = driver.find_element_by_tag_name("footer")driver.execute_script("arguments[0].scrollIntoView();", footer)


To scroll the page to the end, you could simply send the END key:

from selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver = webdriver.Firefox()driver.get("http://stackoverflow.com/search?tab=newest&q=selenium")driver.find_element_by_tag_name("body").send_keys(Keys.END)

You could also scroll the full height :

driver = webdriver.Firefox()driver.get("http://stackoverflow.com/search?tab=newest&q=selenium")driver.execute_script("window.scrollBy(0, document.documentElement.scrollHeight)")


Hey I found another solution that worked perfectly for me. Check this answer here. Also this implementation: driver.find_element_by_tag_name("body").send_keys(Keys.END) does not work for pages that that use infinite scrolling design.