如何使用 watir 在弹出窗口中输入密码?

2024-03-26

我正在编写一些 watir 测试用例:

browser.goto "http://egauge2592.egaug.es/"
browser.link(:href,"/settings.html").click
browser.text_field(:index,4).set("some text")
browser.button(:id,"save_button").click

然后将打开“需要身份验证”对话框,询问用户名和密码。

无论我如何尝试,我都无法访问文本字段。

I tried send_keys和 JavaScript。

我也尝试过Watir.autoit但它说未定义的方法。

我在带有 FireFox 浏览器的 Ubuntu 机器上使用 watir。

如何填写该对话框的用户名和密码字段? 我可以使用 browser.alert.set 输入用户名,但只能设置用户名,无法访问密码字段。


最近写了一个firefox插件来解决这个问题。我还没有在无头 Firefox 上尝试过,但它可能会起作用......值得一试。详细信息请参见以下内容:

http://www.natontesting.com/2012/10/06/firefox-plugin-test-automation-password-manager/ http://www.natontesting.com/2012/10/06/firefox-plugin-test-automation-password-manager/

要使其与 watir 一起工作,请尝试以下操作:

browser = Watir::Browser.new
#go to a page that won't bring up the authentication dialog...
browser.goto 'http://www.google.co.uk'

#prepare the script...
pass_man_update_script = <<-SCRIPT
var addCredentialsEvent = new CustomEvent("add_credentials_to_passman", {
  detail: {
    host: 'http://secure.example.com',
    username: 'bob',
    password: 'P45sword'
  }
});
window.dispatchEvent(addCredentialsEvent);
SCRIPT

#inject the script into the browser:
browser.execute_script pass_man_update_script

#go to the page that prompts the dialog box...
browser.goto "http://secure.example.com"
#you should now be past the dialog box!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 watir 在弹出窗口中输入密码? 的相关文章

随机推荐