selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document的解决方法

最近遇到了这个问题,在网上看了很多方法,尝试了很多种,还是没有解决我的问题,现在终于搞定了,现在把代码整理下:

我所要做的事情,就是判断图片中的活动名称中是否有“夺宝奇兵”,如果没有,则点击【添加夺宝奇兵】,但是一直报错 Message: stale element reference: element is not attached to the page document,具体解决如下:

 

 

list_data = dr.find_elements(By.TAG_NAME,"span")
len_list = len(list_data)
a = []
b = 0
while b<= len_list:
for i in list_data:
a.append(i.text)
b = b+1
if "夺宝奇兵" not in a:
dr.find_element(By.LINK_TEXT,"添加夺宝奇兵").click()

 

posted @ 2020-12-22 23:52  竹贤  阅读(839)  评论(0编辑  收藏  举报