How to enter password in a popup using watir?

故事扮演 提交于 2019-12-20 16:49:46

问题


I'm writing some watir test cases:

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

then a 'Authentication Required' dialogue opens, asking for username and password .

No matter how I tried, I couldn't access the text fields.

I tried send_keys and JavaScript.

I also tried Watir.autoit but it says undefined method.

I'm using watir on a Ubuntu machine with the FireFox browser.

How to fill in username and password fields of that dialogue box? I was able to enter username with browser.alert.set but could only set username couldn't access password field.


回答1:


I wrote a firefox plugin to deal with this problem recently. I haven't tried it with headless Firefox, but it might work... worth a try. See the following for details:

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

To get it working with watir, try the following:

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!



回答2:


I use watir-webdriver instead and this (http://watirwebdriver.com/basic-browser-authentication/) works for me.




回答3:


Just put your basic auth credentials in the url:

browser.goto "http://user:pass@egauge2592.egaug.es/"


来源:https://stackoverflow.com/questions/12710287/how-to-enter-password-in-a-popup-using-watir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!