无法处理基本身份验证窗口

发布于 2024-10-31 17:19:12 字数 1696 浏览 1 评论 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

}

发生的情况是用户名和密码从未在身份验证窗口中输入,并且超时错误显示。

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

我修改了 WindowHelper.rb 中方法 logon 的代码并尝试执行此操作。

// 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

}

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

Iam working on Popup windows i.e. handling Basic Authentication windows.Please find the below code which I am trying to run the test with

{

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

}

What happens is the User Name and Password is never typed in the Authentication Window and Timedout Error is displayed.

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

Is this the problem with the version of Ruby 1.9.2 which I am using?

I modified the code for a method logon in the WindowHelper.rb and tried doing it.

// 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
 }

Code which I modified to and found working sometimes

{

        def logon(title,name,password)

        @autoit.WinWait title, ""

        @autoit.Send name

        @autoit.Send "{TAB}"

        @autoit.Send password

        @autoit.Send "{ENTER}"

    end

}

I have tried for the solution in various blogs. Suggest me if I am missing something.

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

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

发布评论

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

评论(1

美男兮 2024-11-07 17:19:12

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

尝试 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

I guess your script stopped before handling BASIC Authentication because your error text said Timeout error occured at wait method which is used in goto method.

try ie.navigate method instead of goto method like the following

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文