51Testing软件测试论坛

标题: selenium自动化:为什么不能点击登录? [打印本页]

作者: 泡沫666    时间: 2015-7-7 20:11
标题: selenium自动化:为什么不能点击登录?
#coding=UTF-8
'''
Created on 2015-7-6

@author: paomo
'''

from selenium import webdriver

MyBrowser=webdriver.Firefox()
MyBrowser.get("https://www.baidu.com/")

MyBrowser.find_element_by_xpath("/html/body/div[4]/div/div/div[3]/a[6]").click()

if __name__ == '__main__':
    pass

报错信息:
Traceback (most recent call last):
  File "E:\Users\aidupeng\workspace\test\test1.py", line 14, in <module>
    MyBrowser.find_element_by_xpath("/html/body/div[4]/div/div/div[3]/a[6]").click()
  File "C:\Python27\lib\site-packages\selenium-2.40.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 221, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Python27\lib\site-packages\selenium-2.40.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 681, in find_element
    {'using': by, 'value': value})['value']
  File "C:\Python27\lib\site-packages\selenium-2.40.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 164, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium-2.40.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: u'Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/div/div/div[3]/a[6]"}' ; Stacktrace:
    at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/aidupeng/appdata/local/temp/tmpjqsgdv/extensions/fxdriver@googlecode.com/components/driver_component.js:8904)
    at FirefoxDriver.prototype.findElement (file:///c:/users/aidupeng/appdata/local/temp/tmpjqsgdv/extensions/fxdriver@googlecode.com/components/driver_component.js:8913)
    at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/aidupeng/appdata/local/temp/tmpjqsgdv/extensions/fxdriver@googlecode.com/components/command_processor.js:10878)
    at DelayedCommand.prototype.executeInternal_ (file:///c:/users/aidupeng/appdata/local/temp/tmpjqsgdv/extensions/fxdriver@googlecode.com/components/command_processor.js:10883)
    at DelayedCommand.prototype.execute/< (file:///c:/users/aidupeng/appdata/local/temp/tmpjqsgdv/extensions/fxdriver@googlecode.com/components/command_processor.js:10825)



作者: joney2015    时间: 2015-7-7 22:42
xpath 路径请使用://html/body/div[4]/div/div/div[3]/a[6]
作者: joney2015    时间: 2015-7-7 22:43
请使用: //html/body/div[4]/div/div/div[3]/a[6]
作者: joykao    时间: 2015-7-8 10:51
xpath的值写错鸟,推荐款检测xpath的工具,操作见博客 http://anthonygao.blog.51cto.com/8653110/1418857





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2