2

I'm trying to scroll to the bottom of the web page but it scrolls only once and stay on that position and there's a big part of the page left.

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

Do you know where could be the problem?

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

Milano
  • 18,048
  • 37
  • 153
  • 353

3 Answers3

2

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

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

To find the element, there are many options available (see here)

See here for more info

and these SO questions/answers:

first

second

Community
  • 1
  • 1
Pynchia
  • 10,996
  • 5
  • 34
  • 43
  • Thanks for your answer, it seems good but I can't find oou what to put here: element = driver.find_element_by_... Could you give me a hint? Thanks – Milano Jun 19 '15 at 11:07
0

2 easy ways:

hardcode so it goes all the way down for sure:

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

or find the location of an element in the bottom of the page and scroll to its location:

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

I tried this and it worked for me.

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