I have tried driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
after the page has loaded to no avail. It simply does nothing.
Why isn't it working? Is there another method I can use.
There are several ways to scroll the page with Selenium.
Additionally to
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
You can try
from selenium.webdriver.common.keys import Keys
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)
But the most powerful way that normally works even when the previously methods will not is:
Locate some element out of the visible screen, maybe on the bottom of the page and apply on it the following
bottom_element = driver.find_element(By.XPATH, bottom_element_locator)
bottom_element.location_once_scrolled_into_view
This originally intend to return you coordinates (x
, y
) of element on page, but also scroll down right to target element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With