【问题标题】:Unable to handle Basic Authentication windows无法处理基本身份验证窗口
【发布时间】:2011-04-13 12:48:19
【问题描述】:

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

{

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

我修改了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

}

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

【问题讨论】:

  • 我想我有点困惑,当我在谷歌登录时,它不会弹出一个单独的窗口进行身份验证。这是您站点的 IT 人员为了访问代理服务器或其他什么而强加的某种 Windows 级别的身份验证吗?
  • 能否给出超时错误的错误文本?
  • 嗨 Chuck,在我的情况下,我确实有本地 IT 团队完成的 Windows 级别身份验证以获得对代理服务器的访问权限,即我获得此身份验证窗口的原因。显示以下错误消息并且永远不会执行。
  • >ruby google_search.rb C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:494:in @ 987654328@block in wait' 来自 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' 来自 google_search .rb:96:in `
    ' >退出代码:1
  • 您知道作为作者您应该能够编辑原始问题吧?

标签: ruby watir autoit


【解决方案1】:

我猜你的脚本在处理基本身份验证之前停止了,因为你的错误文本说超时错误发生在 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

【讨论】:

  • 在使用 "ie.ie.navigate "google.com"" 时,已处理身份验证窗口,显示空白页面并产生以下错误消息:>ruby google_search.rb C:/Ruby192/lib /ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:403:in method_missing': unknown property or method: hwnd' (NoMethodError) HRESULT 错误代码:0x800706ba RPC 服务器不可用。来自 C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:403:in close' from google_search.rb:107:in
    ' #<0x1356d50 autoit="#<WIN32OLE:0x1356cd8">
猜你喜欢
  • 1970-01-01
  • 2017-12-24
  • 1970-01-01
  • 2018-09-14
  • 2013-05-30
  • 2020-10-22
  • 2021-10-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多