python selenium 元素不再附加到DOM,它不在当前框架上下文中,或者文档已刷新

 raise exception_class(message, screen, stacktrace) selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <span> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been

selenium的定位方式不会直接出异常,类似find_element_by_id这方法,如果不存在元素,则返回None,你可以对其判断再执行对应操作。

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

自己回答一波,问题解决了 是这么回事,上一个页面需要双击进入,因而用了actionchains模块,现在大多数CSDN上关于actionchains的用法都是这样 actionchains(driver).double_click(*).perform()

因为一直都页面跳转成功了,也就没有认为是这一步,哪怕编译器回溯了。后来去掉.perform(),就成功了。不知道是因为库更新了,还是我的webdriver版本低的缘故。但是应该是重复操作导致,在页面跳转后,在进行perform,用于操作上一个页面,dom肯定更新了。但是比较奇怪的是报错报的是当前页面的dom的问题。如果以上看法有错,欢迎指正。