Java 无法处理警报消息

Java 无法处理警报消息,java,selenium,selenium-webdriver,selenium-chromedriver,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在使用Java和Selenium编写一个测试。我的Chrome浏览器版本是52.0,selenium驱动程序是2.53。我的目标网页上有一个按钮,单击该按钮后会显示一个警报。我总是用: try{ wait.until(ExpectedConditions.elementToBeClickable(By.xpath("blabla"))).click(); Thread.sleep(1000); wait.un

我正在使用Java和Selenium编写一个测试。我的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();
    }
处理警报,但从今天早上开始,当test单击按钮时,警报会弹出,但随后会抛出:

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();

我在Chrome上遇到了同样的问题,当时正在点击的按钮在iframe中。刚刚在firefox中运行了测试。请参阅chromium bug tracker中记录的这两个问题-


您正在使用chromedriver 2.20版

此处:被告知在2.22版本中此问题已修复


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

但它昨天就开始工作了!!发生了什么事?我们必须使用Chrome:(尝试在按钮单击行捕获异常,它抛出WebDriverException,然后检查警报处理代码是否有效。你也可以尝试使用sleep。请查看编辑过的问题。它在第一行抛出错误,它不能进入thread.sleepit进入
driverChrome.switchTo().alert().accept();
并等待三次。您的chromedriver版本是什么?似乎是2.20…逐步升级到2.22和2.23,然后再次检查
     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();