2011-04-13 68 views
0

荫的弹出式窗口的工作即处理基本身份验证windows.Please找到下面的代码,我试图运行与无法处理基本身份验证窗口

{ 

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 

} 

我已经尝试了各种博客的解决方案。建议我如果我错过了一些东西。

+0

我想我是有点糊涂转到方法,当我登录在谷歌不会弹出认证一个单独的窗口。这是否是由您的站点的IT人员施加的一些Windows级别身份验证,以获得对代理服务器的访问权限? – 2011-04-13 17:23:59

+1

你能给出超时错误的错误文本吗? – 2011-04-13 17:24:31

+0

喜查, 在我来说,我确实有当地IT团队做访问代理服务器的Windows级认证,即我得到这个认证窗口的原因。 显示下面的错误消息,执行不会发生。 – ajazz 2011-04-14 05:23:30

回答

0

我猜处理基本身份验证,因为您的错误文中说,在这被转到方法使用wait方法发生超时错误之前,你的脚本停止。

尝试ie.navigate方法,而不是像下面

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 
+0

关于使用“ie.ie.navigate”http://www.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:在'method_missing'中:未知属性或方法:'hwnd' (NoMethodError) HRESULT错误代码:0x800706ba RPC服务器不可用。 \t from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:403:在close中 \t from google_search.rb:107 :在'

' #> 零 >退出代码:1 – ajazz 2011-04-14 11:25:47

+0

即通过修改代码精美制作: 需要 '的Watir /即' 需要' WIN32OLE” 需要 '的Watir/WindowHelper' 即=的Watir :: IE.new ie.ie.navigate “http://www.google.com” 帮手= WindowHelper.new 提出helper.inspect x = helper.logon('Connect to fproxy1','Mohammed.Ali1','WE8SRgmC') puts x.inspect ie.ie.navigate“http://www.yahoo.com” ie.close 非常感谢Yutaka。 ajazz。 – ajazz 2011-04-14 11:33:40

+0

如果有效,你为什么不接受答案? – 2011-04-14 22:16:21