1

I'm currently in CH11 from the "Automate the Boring Stuff with Python" book and I'm going over the Selenium module. I'm trying to move to the end of a page but I'm getting some problems. I also tried to look similar problems in this site and tried the solutions suggested without success unfortunately. Here's my code, when I type it into the IDLE Shell:

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')
type(htmlElem)
<class 'selenium.webdriver.firefox.webelement.FirefoxWebElement'>
htmlElem.send_keys(Keys.END)  # Error

Exception -:

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    htmlElem.send_keys(Keys.END)
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 347, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 494, in _execute
    return self._parent.execute(command, params)
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not visible

Apparently the html element is not visible? I don't understand how so since it seems to locates the html element just fine as seen on the code without any problems but the Key.ENTER is where I'm getting the error. Any help would be appreciated.

3
  • Did you try locating the element by some other attribute ? Commented Oct 26, 2016 at 7:22
  • 1
    Try browser.find_element_by_tag_name('body'). This works for me Commented Oct 26, 2016 at 7:26
  • Thanks a lot Andersson, it works now. Commented Oct 26, 2016 at 21:14

1 Answer 1

2

Just tested the following with Chrome driver and it works (It should also work with Firefox):

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

browser = webdriver.Chrome()
browser.get('http://nostarch.com')
body_elem = browser.find_element_by_tag_name('body')
body_elem.send_keys(Keys.END)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @ettanany it's working now. Do you know why it didn't worked with 'html' though?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.