[英]How to check if an html element is attached to the page document
所以我在 python 和 selenium 中使用了一个循环来不断检查 html 元素列表的属性,但是有时其中一个元素会从文档中分离出来。 当我尝试检查已分离元素的属性时,它会抛出错误“过时的元素引用”。 我已经对其进行了搜索,并从 selenium 中找到了“NoSuchElementException”,据说这可以帮助我避免这个问题,但是我不知道谁来正确实现它。 “NoSuchElementException”的任何其他解决方案/帮助都会很棒:D
基本上,您想将在 try except 语句中引发错误的代码包装起来。 像这样
try:
#this will always run
#some code - eg. check element attributes
except NoSuchElementException:
# this will be executed if NoSuchElementException error is raised by code in try block
# here you can do whatever you need
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.