TA的每日心情 | 无聊 2016-8-9 16:39 |
---|
签到天数: 9 天 连续签到: 1 天 [LV.3]测试连长
|
同一个元素,用不同的方法定位,有时候会报错是为什么?
元素:
<input class="inputstyle" id="u" name="u" value="" tabindex="1" type="text">
代码:
# coding = utf-8
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("https://mail.qq.com/")
driver.find_element_by_id("u").clear()
driver.find_element_by_id("u").send_keys("12345678")
运行后报错:Traceback (most recent call last):
File "C:\Python34\2222222222.py", line 7, in <module>
driver.find_element_by_id("u").clear()
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 744, in find_element
{'using': by, 'value': value})['value']
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"u"}
有人知道为什么吗?急急急
|
|