Selenium脚本将异常抛出为org.openqa.selenium.UnhandledAlertException,即使没有Alert

时间:2018-07-09 12:53:28

标签: selenium unhandled-exception

我正在运行基于Java并使用Firefox gecko驱动程序的硒脚本。该脚本在导航到页面时会引发异常并终止“ UnhandledAlertException”。手动导航时,页面上没有任何警报。请对此提供帮助。

2 个答案:

答案 0 :(得分:0)

您可以在运行时调试脚本的同时,通过try / catch解决此问题:

try {
  // execute your selenium script here
} catch (UnhandledAlertException unhandledAlertException) {
  // continue script on exception
}

答案 1 :(得分:0)

您可以在创建驱动程序实例时进行处理。下面的代码在c#中。 希望这能解决您的问题。

FirefoxOptionsoptions = new FirefoxOptions
        {              
            UnhandledPromptBehavior = UnhandledPromptBehavior.Accept,                                           
        };
driver = new FirefoxDriver(options);