【问题标题】:Selenium 2.18.0 - UnhandledAlertException upon driver initialization, how can you handle it?Selenium 2.18.0 - 驱动程序初始化时出现 UnhandledAlertException,如何处理?
【发布时间】:2012-02-03 17:58:13
【问题描述】:

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

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

但是如果我打电话给

driver = new InternetExplorerDriver();

它会导致 Modal dialog present Exception,因为我当前的系统需要代理凭据,这些凭据由循环的 auto-it 脚本填充(以防万一有人需要它):

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

感谢您的宝贵时间

【问题讨论】:

    标签: exception selenium unhandled-exception


    【解决方案1】:

    如果您的系统需要代理凭据,您应该能够通过您所需的功能将其传递到驱动程序中。

    请参阅 http://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object 了解使用方法。

    【讨论】:

    • 但在我的情况下,我可能很幸运,因为它是一个可以处理的代理请求,仍然......如果这将是网站关于其他事情的警报,你怎么能启动你的如果您在初始化之前已经收到异常,驱动程序来处理网站?
    猜你喜欢
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2021-12-17
    相关资源
    最近更新 更多