[英]How to locate element using text() facing exception(selenium+python)?
[英]Using Selenium+Python, I am finding an element with the find element command, but the element is dynamic, how can I prevent it throwing an exception?
所以我使用 find_element 来定义这样的变量
WinCondition = driver.find_element(By.XPATH, "//div[@class='bonus-game-state back bonus-game-end red']")
然而元素是动态的,这是故意的,但是当代码没有找到元素时,它抛出异常并结束整个过程,我只是想让它如果没有找到元素什么都不做,因为有时元素是在页面上,有时不是
我只希望它在找到元素时做某事,如果找不到则什么也不做。 说得通?
我怎样才能防止它抛出异常?
检查一个元素是否存在然后做一些事情否则跳过它。
try:
if winCondition.exists():
do somthing
else:
skip it.
except:
print("element not exists")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.