1

I'd like to scroll to the bottom of a page using Selenium with the Firefox driver.

Here is what I have so far:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser=webdriver.Firefox()
browser.get('http://nostarch.com')
htmlElem=browser.find_element_by_tag_name('html')
htmlElem.send_keys(Keys.END)    #scrolls to bottom

Unfortunately, my code fails with the following exception:

Traceback (most recent call last):
  File "<pyshell#26>", line 1, in <module>
    htmlElem.send_keys(Keys.END)    #scrolls to bottom
  File "C:\Users\academy\AppData\Local\Programs\Python\Python35\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 352, in send_keys
    'value': keys_to_typing(value)})
  File "C:\Users\academy\AppData\Local\Programs\Python\Python35\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 501, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\academy\AppData\Local\Programs\Python\Python35\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "C:\Users\academy\AppData\Local\Programs\Python\Python35\lib\site-
packages\selenium\webdriver\remote\errorhandler.py", line 194, in 
 check_response
    raise exception_class(message, screen, stacktrace)
 selenium.common.exceptions.ElementNotInteractableException: Message: 
 Element is not visible
Taku
  • 31,927
  • 11
  • 74
  • 85
Abdul Khan
  • 67
  • 8
  • Possible duplicate of [Selenium Element not visible exception](https://stackoverflow.com/questions/27927964/selenium-element-not-visible-exception) – Alessandro Da Rugna Nov 10 '17 at 13:28

2 Answers2

0

Use WebDriverWait (explicit wait) till element to be visible i dont know too much about python so give just general syntax

from selenium import webdriver
from selenium.webdriver.common.keys import Keys


browser=webdriver.Firefox()
browser.get('http://nostarch.com')
htmlElem=WebDriverWait(browser, 5).until(
    EC.presence_of_element_located((By.find_element_by_tag_name, "html"))
htmlElem.send_keys(Keys.END)
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
0

To scroll to the bottom of a page using Selenium you can use :

  • Python

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

    ((JavascriptExecutor)driver).executeScript("window.scrollTo(0, document.body.scrollHeight);");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352