Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Chrome驱动程序(Webdriver)上处理警报窗口_Java_Google Chrome_Selenium_Webdriver - Fatal编程技术网

Java 在Chrome驱动程序(Webdriver)上处理警报窗口

Java 在Chrome驱动程序(Webdriver)上处理警报窗口,java,google-chrome,selenium,webdriver,Java,Google Chrome,Selenium,Webdriver,我在处理Chrome弹出的警报时遇到了问题,我一直遇到以下错误。org.openqa.selenium.UnhandledAlertException:意外警报打开 (会话信息:chrome=29.0.1547.66) (驱动程序信息:chromedriver=2.3,平台=Windows NT 5.1 SP3 x86) 以下是我到目前为止所做的尝试。当我进入显示错误的页面时: driver.switchTo().alert.accept(); 也试过了 Alert alert = dri

我在处理Chrome弹出的警报时遇到了问题,我一直遇到以下错误。org.openqa.selenium.UnhandledAlertException:意外警报打开 (会话信息:chrome=29.0.1547.66) (驱动程序信息:chromedriver=2.3,平台=Windows NT 5.1 SP3 x86)

以下是我到目前为止所做的尝试。当我进入显示错误的页面时:

driver.switchTo().alert.accept(); 
也试过了

 Alert alert = driver.switchTo().alert();
 alert.accept();
同样的错误

如果有任何解决方案,我们将不胜感激。

事实上,如果您没有正确处理警报,或者在关闭警报之前对驱动程序实例执行任何操作,则会出现未处理的警报异常

范例

步骤1:单击按钮//这将导致获取警报

步骤2://这里您需要提醒句柄


在步骤2中,如果您对驱动程序实例执行任何其他操作,它将引发未处理的AlertException异常,而不是处理警报。

可能是您的ChromeDriver版本。我不建议总是更新到最新版本的东西。缺陷比比皆是


我使用的是ChromeDriver win32_2.0,运行良好

我在IE上遇到了这个问题。但通过两个简单的更改,它开始像在FF下一样工作:
1) 根据建议,我在创建IEDriver时设置了另一个选项-unexpectedAlertBehaviour=Ignore
2) 我还让WebDriverWait发出警报,一开始就将隐式等待设置为“0”-根据@Santossarma的说法,这是另一个问题。


可能也是Chrome的一个解决方案。

我尝试捕获stackoverflow错误,这对我来说是一个解决办法

try
{   
    driver.findElement(By.xpath('xpath')).click(); // command that will trigger the alert window
}
catch (StackOverflowError e)
{
    driver.switchTo().alert().dismiss(); // or driver.switchTo().alert().accept();
    // the rest of the scripts can be added here
}

如果无法使用驱动程序实例,如何使用它?因为如果不使用驱动程序isntance,我无法创建警报实例。这是我用来处理警报公共静态布尔值manejarAlertas(){boolean alerta=true;尝试{//Espero 10 segundo como maximo a que aparezca el mensaje de alert.WebDriverWait wait wait=new WebDriverWait(driver,20);wait.untill(ExpectedConditions.alertIsPresent());driver.switch().alert().accept();//Si esta presente hago单击en确定//alert.accept();}catch(异常e){alerta=false;}return alerta;}而不是WebDriverWait,只需尝试静态等待即可。我的意思是放一些线。睡眠(3000);试试同样的方法。如果它起作用,意味着我们可以考虑等待逻辑。尝试过这样做,问题仍然存在,我甚至尝试过使用ActionKey和press Key。Esc和它的相同错误。只是好奇,你试过FirefoxDriver吗?工作正常吗?