如何使用watir在弹出窗口中输入密码?
我正在写一些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
然后打开“需要validation”对话框,询问用户名和密码。
无论我怎么试,我都无法访问文本字段。
我试过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/
要使其与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!
我使用watir-webdriver代替这个(http://watirwebdriver.com/basic-browser-authentication/)适合我。
只需将您的基本身份validation凭据放入url:
browser.goto "http://user:pass@egauge2592.egaug.es/"