【问题标题】:cannot handle alert message无法处理警报消息
【发布时间】:2016-08-20 03:30:08
【问题描述】:

我正在使用 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();

【问题讨论】:

    标签: java selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    您使用的是 chromedriver 2.20 版。

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

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

    【讨论】:

      【解决方案2】:

      当被点击的按钮位于 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();
      

      【讨论】:

      • 但是昨天还在工作!!发生了什么 ?我们必须使用 Chrome :(
      • 尝试在按钮单击行捕获异常,它会抛出WebDriverException,然后检查警报处理代码是否有效。你也可以尝试睡眠。
      • 请查看已编辑的问题。它在第一行抛出错误,它没有;''t get to thread.sleep
      • 它到达 driverChrome.switchTo().alert().accept(); 并永远等待 tehre
      • 您的 chromedriver 版本是多少?好像是2.20的。。。逐步升级到2.22和2.23再检查一遍
      猜你喜欢
      • 2021-05-25
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2013-07-18
      相关资源
      最近更新 更多