0

我正在处理弹出窗口,即处理基本身份验证窗口。请找到我正在尝试运行测试的以下代码

{

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版本的问题吗?

我修改了一个方法的代码logonWindowHelper.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

}

我已经在各种博客中尝试过解决方案。如果我遗漏了什么,建议我。

4

1 回答 1

0

我猜您的脚本在处理基本身份验证之前停止了,因为您的错误文本说超时错误发生在 goto 方法中使用的等待方法中。

尝试 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
于 2011-04-14T06:32:10.437 回答