【发布时间】:2016-10-27 14:52:44
【问题描述】:
我正在使用 Python 在 Selenium 中编写自动化测试。一种元素可能存在也可能不存在。我正在尝试使用以下代码处理它,它在元素存在时起作用。但是当元素不存在时脚本失败,如果元素不存在,我想继续下一条语句。
try:
elem = driver.find_element_by_xpath(".//*[@id='SORM_TB_ACTION0']")
elem.click()
except nosuchelementexception:
pass
错误 -
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:{"method":"xpath","selector":".//*[@id='SORM_TB_ACTION0']"}
【问题讨论】:
标签: python python-3.x selenium selenium-webdriver