Selenium 2.18.0 - 驱动程序初始化时的UnhandledAlertException,你如何处理它?

时间:2012-02-02 15:27:17

标签: exception selenium unhandled-exception

我做错了并将我的 pom.xml 更新为selenium 2.18.0 现在,操作期间的 UnhandledAlertException 是新功能:

  

Firefox和IE中的警报处理:如果操作期间出现警报,则抛出UnhandledAlertException。未处理的警报也被驳回,以减轻重复的异常。

但如果我打电话

driver = new InternetExplorerDriver();

导致模态对话框出现异常,因为我当前的系统需要代理凭据,这些凭据由循环自动脚本填充(以防有人需要):

Dim $arrTitle[2] = ["Authentification required", "Windows Security"]
While 1
For $sTitle In $arrTitle
    If WinExists($sTitle) Then
        WinActivate($sTitle);
        Send("{HOME}");
        Send("+{END}");
        Send("{DEL}");
        Send("user");
        Send("{TAB}");
        Send("{HOME}");
        Send("+{END}");
        Send("{DEL}");
        Send("password");
        Send("{ENTER}");
        Sleep(1000)
    EndIf
Next
Sleep(500)
WEnd

那么如何防止此异常呢?如果我只是

try { driver = new InternetExplorerDriver(); }
catch(UnhandledAlertException e) {}

我将收到 driver = null

感谢您的时间

1 个答案:

答案 0 :(得分:1)

如果您的系统需要代理凭据,您应该可以将所需的功能传递给驱动程序。

请参阅http://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object了解要使用的内容。