背景: 执行driver.execute_script("return document.readyState;")方法时因为当前浏览器有alert弹窗,导致报错:selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text
详细报错信息如下:
raise exception_class(message, screen, stacktrace, alert_text)
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: {
Alert text :
Message: unexpected alert open: {
Alert text : }
(Session info: chrome=90.0.4430.212

本文介绍了一种在Selenium WebDriver中执行JavaScript代码时如何处理弹出的alert的方法。当浏览器出现alert时,直接执行JavaScript可能会导致异常。文章提供了一个Python示例,通过检查并处理alert来确保JavaScript代码能够正常运行。
最低0.47元/天 解锁文章
805

被折叠的 条评论
为什么被折叠?



