Selenium scrolling to the bottom does not work as expected

I'm trying to scroll to the bottom of a webpage, but it only scrolls once and stays at that position, and most of the rest of the page is there.

I am using this: _inst.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

Do you know where the problem might be?

EDIT: Is there a way to tell selenium that it should scroll to the absolute bottom of the page, or that it should scroll a certain number of times? For example, 5?

+2


source to share


3 answers


To scroll to the bottom of the page, you can send CTRL + END to one of your elements:

from selenium.webdriver.common.keys import Keys
element = driver.find_element_by_ ...
element.send_keys(Keys.CONTROL , Keys.END)

      

To find an item, there are many options available (see here )

See here for more information



and these SO questions / answers:

first

second

+1


source


2 easy ways:

so it goes all the way down:

_inst.driver.execute_script("window.scrollTo(0, 10000);")

      



or find the location of the element at the bottom of the page and highlight its location:

element = find_element('footer')
position = element.location[:y]
_inst.driver.execute_script("window.scrollTo(0, position);")

      

0


source


I tried this and it worked for me.

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

      

0


source







All Articles