51Testing软件测试论坛

标题: help+ [打印本页]

作者: zhang_anne    时间: 2017-5-5 15:30
标题: help+
1.<a id="LinkBtn_Life" href="javascript:__doPostBack('LinkBtn_Life','')">更多...</a>

2.driver.find_element_by_id("LinkBtn_Life").click()  通过id 触发单击事件。会报如下错误,好奇怪!

*****************
raceback (most recent call last):
  File "D:\张艳\test\python\Irhate\login.py", line 20, in <module>
    driver.find_element_by_id("LinkBtn_Life").click()
  File "C:\Users\IRH-PC\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 282, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Users\IRH-PC\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 784, in find_element
    'value': value})['value']
  File "C:\Users\IRH-PC\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 249, in execute
    self.error_handler.check_response(response)
  File "C:\Users\IRH-PC\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="LinkBtn_Life"]

作者: 梦想家    时间: 2017-5-5 15:40
定位不对么 别的定位方式也会报错么?
作者: jingzizx    时间: 2017-5-5 17:21
帮顶
作者: cq520131517    时间: 2017-5-8 09:09
1.看看你这id前面有没有frame框架,有,则转换一下switch_to_frame()。。。。
2.加个时间等待,time.sleep(2)...
3.看看是不是id,关闭页面,再打开查看元素的id有没有变化。。。。




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