过时的元素异常处理在 Selenium 中不起作用

Stale element exception handling is not working in Selenium

提问人:Mahdi 提问时间:11/17/2023 最后编辑:Mahdi 更新时间:11/17/2023 访问量:26

问:

以下代码无法处理过时的元素异常错误:

        website_accessable = False
        try:
            driver.get(addressToVerify)
            website_accessable = True
        except WebDriverException as e:
            if 'net::ERR_SSL_PROTOCOL_ERROR' in str(e):
                print("--- Error: SSL error protocol occurred!")
                return website_accessable
        except TimeoutException:
            print("--- Error: Webpage openning Time out!")
            return website_accessable
        except StaleElementReferenceException:
            print("--- Error: Stale element referenced!")
            return website_accessable               
        except Exception as e:
            print("Error:", str(e))
            return website_accessable

控制台中显示完整错误(触发第二个异常)。 有什么想法吗?

完全错误:

Message: stale element reference: stale element not found
  (Session info: chrome=119.0.6045.123); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception
Stacktrace:
0   chromedriver                        0x0000000101d90d28 chromedriver + 4795688
1   chromedriver                        0x0000000101d882b3 chromedriver + 4760243
2   chromedriver                        0x000000010196188d chromedriver + 407693
3   chromedriver                        0x0000000101967d6f chromedriver + 433519
4   chromedriver                        0x000000010196a0c4 chromedriver + 442564
5   chromedriver                        0x000000010196a20c chromedriver + 442892
6   chromedriver                        0x00000001019a9fa2 chromedriver + 704418
7   chromedriver                        0x00000001019d7ca2 chromedriver + 892066
8   chromedriver                        0x00000001019a3c63                       0x00000001019d7a73 
python selenium-web驱动程序

评论

1赞 John Gordon 11/17/2023
显示完整的错误回溯,并在代码中显示定义/导入的位置。StaleElementReferenceException
1赞 John Gordon 11/17/2023
另外,我看不出怎么会提出这个例外。您确定此代码是发生错误的地方吗?driver.get()
1赞 John Gordon 11/17/2023
该错误回溯并非来自此代码。过时元素异常发生在代码中的其他位置。
1赞 John Gordon 11/17/2023
据我所知,“打开网页”不会导致过时的元素异常。因此,错误一定发生在其他地方。
1赞 John Gordon 11/17/2023
该错误消息从何而来?这不是标准的 Python 异常消息。您确定这是整个堆栈跟踪吗?

答: 暂无答案