我无法使用Watir在IE8上的某个网站上进行基本身份验证。
当我导航(转到)网址时,会显示基本身份验证对话框,显示“连接到'作为标题,用户名,密码编辑字段和确定,取消按钮(通常!)。 在Watir中,在传递以下代码之后:
b = Watir::Browser.new
b.goto '<our url>'
显示对话框,但goto语句永远不会完成。如果我手动取消或登录,那么goto语句会返回一个数字(顺便说一下,这是在IRB中)。
我已经做了很多调查并尝试了各种各样的想法,但现在似乎很难过!
当我们手动登录网站时,我们必须通过以下凭据:
User Name: <domain>\<username>
Password: <password>
我在网址字符串中尝试了这个,即
http://<domain>\<username>:<password>@<url>:<port>
http://lnd\mbartram:mypassword@xxx.xx.xx.xx:xxxx
但是这不能在代码中工作,或者我在地址栏中手动输入。 也许我需要逃避\部分才能让它发挥作用,但是如何?
非常感谢任何帮助。 微米。
答案 0 :(得分:0)
好的,使用一点点黑客但它对我来说一直有效。我使用了一个简单的Wscript.Shell SendKeys方法。见下文:
`start #{theURL]`
loginDialog = WIN32OLE.new('Wscript.Shell')
loginDialog.AppActivate('Connect to #{ip}')
sendKeys = "#{userName}{TAB}"
loginDialog.SendKeys(sendKeys)
sleep(1)
sendKeys = "#{password}{TAB}{ENTER}"
loginDialog.SendKeys(sendKeys)