|
求高手看看,元素如下:<input name="txtusername" id="txtusername" data-val="true" datafield="User.UserName" data-val-required="用户名必须输入" type="text" value="" size="15" class="input input-w240h36">
代码如下:
#coding=utf-8
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("http://www.greenpass-tc.com/WebMain.htm")
time.sleep(2)
driver.find_element_by_id("txtusername").send_keys("sa")
driver.quit()
执行的时候一直提示找不到这个元素,报错:
Traceback (most recent call last):
File "D:\selenium_study\test.py", line 8, in <module>
driver.find_element_by_id("txtusername").send_keys("sa")
File "D:\Python27\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 "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"txtusername"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/zoumin/appdata/local/temp/tmpmlwwor/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///c:/users/zoumin/appdata/local/temp/tmpmlwwor/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/zoumin/appdata/local/temp/tmpmlwwor/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/zoumin/appdata/local/temp/tmpmlwwor/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///c:/users/zoumin/appdata/local/temp/tmpmlwwor/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
xpath也试了,也是不行,求高手大大帮忙解答下是什么问题呀
|
|