我正在使用弹出窗口,即处理基本身份验证窗口。请找到以下代码,我试图用
运行测试{
require 'watir/ie'
require 'win32ole'
require 'watir/WindowHelper'
ie=Watir::IE.new
ie.goto "http://www.google.com"
helper = WindowHelper.new
helper.logon('Connect to proxy1','Mohammed','WE8SR') # where title=Connect to Proxy1 is the auth window,User name= Mohammed and Password=WE8SR.
puts x.inspect
ie.close
}
如果用户名和密码从未在验证窗口中输入,则会显示Timedout Error
。
ruby google_search.rb
C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:494:in sleep': execution expired (Timeout::Error)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:494:in block in wait'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:491:in wait'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:357:in goto'
from google_search.rb:96:in `<main>'
>Exit code: 1
这是我使用的 Ruby 1.9.2 版本的问题吗?
我修改了logon
中方法WindowHelper.rb
的代码并尝试了这样做。
// Actual method in the "WindowHelper.rb" file
{
def logon(title,name = 'john doe',password = 'john doe')
@autoit.WinWait title, ""
@autoit.Send name
@autoit.Send "{TAB}"
@autoit.Send password
@autoit.Send "{ENTER}"
end
}
我修改过的代码,有时会找到工作
{
def logon(title,name,password)
@autoit.WinWait title, ""
@autoit.Send name
@autoit.Send "{TAB}"
@autoit.Send password
@autoit.Send "{ENTER}"
end
}
我在各种博客中尝试过该解决方案。建议我,如果我遗失了什么。
答案 0 :(得分:0)
我猜你的脚本在处理BASIC身份验证之前已经停止了,因为你的错误文本说在goto方法中使用的wait方法发生了Timeout错误。
尝试使用ie.navigate方法代替goto方法,如下所示
require 'watir/ie'
require 'win32ole'
require 'watir/WindowHelper'
ie=Watir::IE.new
ie.ie.navigate "http://www.google.com"
helper = WindowHelper.new
helper.logon('Connect to proxy1','Mohammed','WE8SR') # where title=Connect to Proxy1 is the auth window,User name= Mohammed and Password=WE8SR.
puts x.inspect
ie.close