Watir 无法清除 IE 安全警告

发布于 12-09 05:41 字数 3222 浏览 2 评论 0原文

我正在使用 watir-webdriver 驱动 IE 来测试另一个网站使用 SSL 证书的网站。 (同一网站的生产版本)

当我访问我的网站时,我得到一个如下所示的页面(因为安全证书不好) http://www.zeus.com/sites/default/files/media/warning2.png

watir 文档有一个此问题的解决方法 http://wiki.openqa.org/display/WTR/Security+Alerts my_browser.link(:id, "overridelink").click

当我尝试在 ruby​​ 控制台中运行它时,出现错误。

irb(main):050:0> b.link(:id, "overridelink").click
Selenium::WebDriver::Error::UnexpectedJavascriptError: Unable to find element with xpath == .//a[@id='overridelink']
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/response.rb:45:in `assert_ok'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/common.rb:54:in `new'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/common.rb:54:in `create_response'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/common.rb:35:in `call'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/bridge.rb:410:in `raw_execute'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/bridge.rb:388:in `execute'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/bridge.rb:356:in `find_element_by'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/common/search_context.rb:41:in `find_element'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/locators/element_locator.rb:86:in `find_first_by_multiple'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/locators/element_locator.rb:33:in `locate'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/elements/element.rb:263:in `locate'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/elements/element.rb:245:in `assert_exists'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/elements/element.rb:65:in `click'
        from (irb):50
        from :0irb(main):051:0>

当您查看错误页面的 html 时,肯定存在继续链接。

<tr>
<td >&nbsp;</td>
<td id="continueToSiteAlign" align="left" valign="middle">
    <h4 id="continueToSite">
        <img src="red_shield.png" ID="ImgOverride" border="0" alt="Not recommended icon" class="actionIcon"><A href='' ID="overridelink" NAME="overridelink" >Continue to this website (not recommended).</A>
    </h4>
    </td>
</tr>

有谁知道如何解决这个问题?

I'm using watir-webdriver to drive IE to test a website using a SSL certificate for another website. (the production version of same website)

When I visit my site, I get a page that looks like this (Since the security certificate is bad)
http://www.zeus.com/sites/default/files/media/warning2.png

The watir documentation has a workaround for this http://wiki.openqa.org/display/WTR/Security+Alerts
my_browser.link(:id, "overridelink").click

When I try to run this in the ruby console, I get an error.

irb(main):050:0> b.link(:id, "overridelink").click
Selenium::WebDriver::Error::UnexpectedJavascriptError: Unable to find element with xpath == .//a[@id='overridelink']
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/response.rb:45:in `assert_ok'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/common.rb:54:in `new'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/common.rb:54:in `create_response'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/http/common.rb:35:in `call'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/bridge.rb:410:in `raw_execute'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/bridge.rb:388:in `execute'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/remote/bridge.rb:356:in `find_element_by'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.8.0/lib/selenium/webdriver/common/search_context.rb:41:in `find_element'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/locators/element_locator.rb:86:in `find_first_by_multiple'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/locators/element_locator.rb:33:in `locate'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/elements/element.rb:263:in `locate'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/elements/element.rb:245:in `assert_exists'
        from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.5/lib/watir-webdriver/elements/element.rb:65:in `click'
        from (irb):50
        from :0irb(main):051:0>

When you look at the html for the error page, the continue link is definitely there.

<tr>
<td > </td>
<td id="continueToSiteAlign" align="left" valign="middle">
    <h4 id="continueToSite">
        <img src="red_shield.png" ID="ImgOverride" border="0" alt="Not recommended icon" class="actionIcon"><A href='' ID="overridelink" NAME="overridelink" >Continue to this website (not recommended).</A>
    </h4>
    </td>
</tr>

Does anyone know how to get around this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烟沫凡尘2024-12-16 05:41:03

据我所知,Watir-WebDriver 无法自动避免这种情况。

解决方案是确保 IE 不关心此错误:

  1. “工具”并选择“Internet 选项”
  2. 选择“高级”选项卡
  3. 向下滚动并取消选中“警告证书地址不匹配”

There is no way to avoid this automatically as far as I know with Watir-WebDriver.

The solution is to make sure IE doesn't care about this error:

  1. Tools and select Internet Options
  2. Select the Advanced tab
  3. Scroll down and uncheck Warn about certificate address mismatch
我三岁2024-12-16 05:41:03

我认为这是了解 watir-webdriver 如何使用证书的正确页面: http://watirwebdriver.com/browser -certificates/

不幸的是,我没有看到任何有关 IE 浏览器的信息。

更新:阿利斯特说“我相信您需要手动将证书添加到受信任的根” https://twitter.com/#!/alisterscott/status/124047931945922561

I think this is the right page to see how watir-webdriver works with certificates: http://watirwebdriver.com/browser-certificates/

Unfortunately, I do not see anything about IE browser.

Update: Alister said "I believe you manually need to add the certificate to trusted root" https://twitter.com/#!/alisterscott/status/124047931945922561

逐鹿2024-12-16 05:41:03

我使用的解决方案是使用 autoit 切换到“继续访问网站”,这样就不必一直添加到网站

    autoit=WIN32OLE.new('AutoItX3.Control')
    i=1
    while i < 11 
        autoit.Send("{Tab}")
        i+=1
    end

    autoit.Send("{Enter}")

A solution for this that I use is to use autoit to tab into the 'continue to website', saves having to add to website all the time

    autoit=WIN32OLE.new('AutoItX3.Control')
    i=1
    while i < 11 
        autoit.Send("{Tab}")
        i+=1
    end

    autoit.Send("{Enter}")
陌若浮生2024-12-16 05:41:03

这段代码适用于我的 IE10,它完美地点击了“overridelink”。

browser.goto("javascript:document.getElementById('overridelink').click()")

this code works on my IE10, it clicks "overridelink" perfectly.

browser.goto("javascript:document.getElementById('overridelink').click()")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文