1

我试图让我的代码(使用Watir开发的IE8)与watir-webdriver和IE9一起工作。 目前我有一个等待的问题。watir-webdriver IE9的等待方法

例如

Watir::Wait.until{browser.button(:value, "Login").exists?} 

它不会等待,给我下一个错误

C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/response.rb:50:in `assert_ok': Unable to find element with xpath == .//button[ 
text()='Login'] | .//input[@value='Login' and (@type='button' or @type='reset' or @type='submit' or @type='image')] (Selenium::WebDriver::Error::UnexpectedJavascriptError 
) 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/response.rb:15:in `initialize' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/http/common.rb:58:in `new' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/http/common.rb:58:in `create_response' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/http/default.rb:64:in `request' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/http/common.rb:39:in `call' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/bridge.rb:450:in `raw_execute' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/bridge.rb:428:in `execute' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/remote/bridge.rb:396:in `find_element_by' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/common/search_context.rb:41:in `find_element' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.3.9/lib/watir-webdriver/locators/element_locator.rb:86:in `find_first_by_multiple' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.3.9/lib/watir-webdriver/locators/element_locator.rb:33:in `locate' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.3.9/lib/watir-webdriver/elements/button.rb:53:in `locate' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.3.9/lib/watir-webdriver/elements/element.rb:259:in `assert_exists' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.3.9/lib/watir-webdriver/elements/element.rb:36:in `exists?' 
     from 1.rb:20:in `block in <main>' 
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.12.2/lib/selenium/webdriver/common/wait.rb:36:in `until' 
     from 1.rb:20:in `<main>' 

试图与IE8相同的脚本,并有同样的问题。 当然,我可以用睡眠来解决它,但这不是一个好主意。 如果我在等待之前睡几秒钟,它可以正常工作。如果这立即引起您的测试服务器证书错误页面后,使用“无效”(自签名)证书,那么你必须发生http://rubydoc.info/github/jarib/watir-webdriver/master/Watir/Element#wait_until_present-instance_method

回答

1

试试这个:

browser.button(:value, "Login").wait_until_present 

更多信息两个选项。

1)将您的测试服务器上的证书添加到您的客户端测试系统上的可信根证书颁发机构池中。这使IE将这些证书视为来自可信任的提供商。 (从不为网站上的网站做这个,只适用于你或你公司的某个人控制的测试服务器)

2)硬连线睡眠在那里。

问题的发生是因为IE9在那个证书页面上做了一些特殊的事情,阻止了 javascript,并阻止webdriver访问页面上的任何东西。即使是简单的基本方法,如'browser.text',也会在该页面上失败,更不用说检查现有的元素。登录按钮的第一次检查发生在无效的证书警告页面仍然显示时,这就是导致错误的原因。如果页面从不显示,或者您只等一小段时间,那么您将不会看到该错误。

MS在该页面上所做的工作旨在防止恶意软件站点自动将响应转移到其站点。好东西安全明智,但它也阻止Webdriver访问页面。我怀疑webdriver的人会找到一种解决办法,如果他们这么做的话,我希望MS能够在不久之后关闭他们认为的“安全漏洞”。

为了测试,我确信最好的做法是将测试用例服务器上的自签名证书添加到测试客户端系统上的受信任根提供程序列表中。这消除了警告,并且比在所有自动化中处理它更快,更容易。它还会在用户遇到真正的生产服务器时复制用户体验,这些服务器无疑具有有效的证书,并且从不产生该警告。

我以前一直致力于寻找'围绕'这些东西的脚本的方法,但意识到我只是固执,应该采取更容易实际的路径。

+0

这并没有帮助,但我发现了这个问题。我的用例是next.I通过IE9转到https服务器,并获得证书错误页面。为了处理这个页面,我使用了wscript命令,并且只需单击tab来覆盖链接。等待方法在覆盖链接命令{enter}后进入正确的位置,在这种情况下它会发生切断。如果在overridelink clicked Wait命令按预期工作后再次转到此https服务器。顺便说一句,这个代码适用于FF和铬没有额外的执行命令。 –

0

+0

感谢您的回答,但手动添加证书对我无效,因为每次新服务器版本到达时(每周2-3次),脚本在20多台机器上执行时,我都需要这样做。 –

+0

那么你只需要在那里硬编码一个足够长的睡眠以确保webdriver永远不会尝试访问那个不好的证书页面。或者您可以找到一种方法来获得在这些测试系统上注册为有效的证书。 (也许wscript要做到这一点?)他们每次重建证书吗?另一种选择可能是设置一个本地系统,该系统可以充当“权威”,并为那些可以长期保存的服务器颁发证书。然后将“权限”添加到您的测试系统基础映像中,以便它始终显示为有效。 –