我在Selenium中使用Python编写自动化测试。一个元素可能存在也可能不存在。我试图用下面的代码来处理它,当元素存在时,它可以工作。但当元素不存在时,脚本就会失败,我想在元素不存在时继续下一个语句。
elem = driver.find_element_by_xpath(".//*[@id='SORM_TB_ACTION0']") elem.click() except nosuchelementexception:Error -
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:{"method":"xpath","selector":".//*[@id='SORM_TB_ACTION0']"}