How to enter password in popup menu using watir?

I am writing several watir tests:

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 

The Authentication Required dialog box opens, prompting for a username and password.

No matter how I tried, I could not access the text fields.

I tried send_keys and JavaScript.

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

I am using watir on a Ubuntu machine with a FireFox browser.

How to fill in the username and password fields of this dialog box? I was able to enter the username using browser.alert.set, but I could only set that the username could not access the password field.

+4
source share
3 answers

I wrote a firefox plugin to solve this problem recently. I have not tried this with Headless Firefox, but it might work ... well worth a try. See below for more details:

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

To make it work 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
source

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

+2
source

Just enter your basic credentials in the URL:

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

Source: https://habr.com/ru/post/1437598/


All Articles