我正在尝试使用Selenium
模块在我的大学邮件中输入用户名和密码。这是我想要找到的id的属性值:
<input id="ContentPlaceHolder1_UsernameTextBox" name="username" tabindex="1" placeholder="FAU Net ID" value="" autocomplete="false" type="text">
以下是我试图在我的程序中找到它的方法:
userElem = browser.find_element_by_id('ContentPlaceHolder1_UsernameTextBox')
但这是我遇到的错误:
例外 - :
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"]
谢谢,非常感谢任何帮助。
编辑:
供参考,这是页面
答案 0 :(得分:2)
如果Selenium告诉你它找不到元素,那么它就不存在了。通常有几个可能的原因:
browser.page_source
仔细检查?