无法处理警报消息

cannot handle alert message

我正在使用 JavaSelenium 编写测试。我的 Chrome 浏览器 版本是 52.0,我的 selenium 驱动程序是 2.53。我的目标网页上有一个按钮,单击该按钮后会显示一个警报。我一直使用:

 try{  wait.until(ExpectedConditions.elementToBeClickable(By.xpath("blabla"))).click();
                    Thread.sleep(1000);
                    wait.until(ExpectedConditions.alertIsPresent());
                    driverChrome.switchTo().alert().accept();
   }
    catch(Exception e){
    e.printStackTrace();
    }

处理警报,但从今天早上开始,当测试点击按钮时,警报弹出,但紧接着它抛出:

org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status
from unexpected alert open
 (Session info: chrome=52.0.2743.116)
 (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 33 milliseconds

连二三线都进不去!! 第一行抛出错误

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("blabla"))).click();

当被点击的按钮位于 iframe 中时,我在 Chrome 中遇到过同样的事情。只是 运行 在 firefox 中的测试。参考 chromium bug tracker 中记录的这 2 个问题 -

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1362

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1224

     try{ 
 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("blabla"))).click();

       }
        catch(Exception e){
        e.printStackTrace();
        }
    Thread.sleep(1000);
                        wait.until(ExpectedConditions.alertIsPresent());
                        driverChrome.switchTo().alert().accept();

您正在使用 chromedriver 2.20 版。

此处:https://bugs.chromium.org/p/chromedriver/issues/detail?id=1224&colspec=ID%20Status%20Pri%20Owner%20Summary 被告知在 2.22 版本中此问题已修复。

因此,如果可能,您可以通过将 chromedriver 版本升级到 2.22 来验证您的问题是否已解决。