0

I am trying type the username and password into my University mail using Selenium module. This is the id's attribute value that I'm trying to locate:

<input id="ContentPlaceHolder1_UsernameTextBox" name="username" tabindex="1" placeholder="FAU Net ID" value="" autocomplete="false" type="text">

Here's how I'm trying to find it in my program:

userElem = browser.find_element_by_id('ContentPlaceHolder1_UsernameTextBox')

But this is the error that I'm running into:

Exception -:

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    emailElem = browser.find_element_by_id('ContentPlaceHolder1_UsernameTextBox')
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 269, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
    'value': value})['value']
  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.NoSuchElementException: Message: Unable to locate element: [id="ContentPlaceHolder1_UsernameTextBox"]

Thanks and any help would be greatly appreciated.

EDIT:

for reference this is the page

Link

2
  • 2
    It hard to tell without looking at the page. You can make sure that element is present on the page using DevTools, Firebug etc Commented Oct 27, 2016 at 0:18
  • Doesn't Selenium have a find_element_by_name() function too? You could try that one also, if not use xpath Commented Oct 27, 2016 at 0:26

1 Answer 1

2

If Selenium is telling you it couldn't find the element, then it isn't there. There are typically a few possible reasons for this:

  1. You did something silly like mistyping the element name. Are you sure that's the correct element ID?
  2. You aren't on the page you thought you were. Are you sure you're on the right page? Have you looked at browser.page_source to double-check?
  3. The element isn't there when the page loads, but is added to the page later via Javascript, perhaps after a set time delay or when some event happens such as a mouse click. Does the page have javascript like this?
Sign up to request clarification or add additional context in comments.

3 Comments

Another possibility is that the element is in a different frame (1, 2), in which case the solution is to call driver.switch_to.frame.
Ooo, I always forget about frames!
You know I did brower.page_source and couldn't locate any of the elements, that was the problem. I'm putting this new window's url with into `browser.get(url)' and it's now fixed. Thanks a lot.

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.