selenium中,运行测试用例,报NosuchElementException错误,用try --except 捕获异常

try:

      ele=driver.find_element_by_name('kw')

except  NosuchElementException as msg:

      print '查找元素异常原因:%s'%msg

else:
      ele.click()

 

selenium常见异常

1.NoSuchElementException:没有找到元素

2.NoSuchFrameException:没有找到iframe

3.NoSuchWindowException:没找到窗口句柄handle

4.NoSuchAttributeException:属性错误

5.NoAlertPresentException:没找到alert弹出框

6.lementNotVisibleException:元素不可见

7.ElementNotSelectableException:元素没有被选中

8.TimeoutException:查找元素超时

 

posted @ 2017-12-21 15:00  Joan姐  阅读(2120)  评论(0编辑  收藏  举报