|
进入新浪首页,想点击【NBA】这个Link
<a href="http://sports.sina.com.cn/nba/">NBA</a>
然后使用Xpath
driver.find_element_by_xpath('//a[href="http://sports.sina.com.cn/nba/"]').click()_
然后运行到这一步就报错了
Traceback (most recent call last):
File "D:/testspace/webTest.py", line 19, in <module>
driver.find_element_by_xpath('//a[href="]http://sports.sina.com.cn/nba/"]').click()
File "D:\tools\python2.7.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 230, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "D:\tools\python2.7.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 662, in find_element
{'using': by, 'value': value})['value']
File "D:\tools\python2.7.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "D:\tools\python2.7.9\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element
(Session info: chrome=40.0.2214.93)
(Driver info: chromedriver=2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c29),platform=Windows NT 6.1 SP1 x86)
显示没有[Message: no such element]这个元素。
请教各位这是什么情况呀?
因为这个写法是按照教程写的
以下是教程内容
【xpath:link
driver.find_element_by_xpath("//a[@href='http://www.baidu.com/']").click()
#有个叫a 的标签,他有个链接href='http://www.baidu.com/ 的元素】
希望得到指点,谢谢
|
|