TA的每日心情 | 开心 2016-10-31 11:34 |
---|
签到天数: 16 天 连续签到: 1 天 [LV.4]测试营长
|
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://mail.163.com/")
driver.find_element_by_id("lbNormal").click()
driver.find_element_by_xpath("//form/div/div/div[2]/input").send_keys("username")
driver.find_element_by_class_name("j-inputtext dlpwd").send_keys("password")
driver.find_element_by_id("dologin").click()
driver.close()
运行结果:
raceback (most recent call last):
File "D:\Python27\Test\autotest\mail163.py", line 6, in <module>
driver.find_element_by_xpath("//form/div/div/div[2]/input").send_keys("username")
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 290, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 744, in find_element
{'using': by, 'value': value})['value']
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//form/div/div/div[2]/input"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/administrator/appdata/local/temp/tmphmt2c9/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///c:/users/administrator/appdata/local/temp/tmphmt2c9/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/administrator/appdata/local/temp/tmphmt2c9/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/administrator/appdata/local/temp/tmphmt2c9/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///c:/users/administrator/appdata/local/temp/tmphmt2c9/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
我将代码中标红行改成通过id、name或class定位,都报找不到元素,请高手指点下,谢谢!
|
|