RE: Handle HTTP Authentication – Authentication required dialog

I’m using Selenium with the Firefox Webdriver to test different events on my Website.

One event leads to a HTTP authentication dialog.
Is there a way to set selenium to always press cancel or to reach a timeout so I don’t hang around and get back the control of the driver?

johnsmithv2 Default Asked on February 25, 2015 in Selenium WebDriver.
Add Comment
4 Answers

Hello,
I found my own solution for the problem. I’m using a modified version of the Firefox add-on AutoAuth. Normally this clicks the OK button when you visited a HTTP Authentication dialog before and saved username and password. I modified the plugin so that it always cancels the dialog.
It’s working very well on Firefox 35.

My Java Code:


public class Main {
public static void main(String[] args) {
// create profile

FirefoxProfile profile = new FirefoxProfile();
//add a extension to firefox

File extension = new File("autoauth-2.1-fx+fn.xpi");

try {

profile.addExtension(extension);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}
WebDriver driver = new FirefoxDriver(profile);

driver.get("http://demo.tanmaysarkar.com/authentication/");

driver.get("http://demo.tanmaysarkar.com/authentication/");
try {

Thread.sleep(10000);

} catch (InterruptedException ex) {

Thread.currentThread().interrupt();

}
driver.quit();
}
}

You have to modify the firefox addon https://addons.mozilla.org/en-us/firefox/addon/autoauth/. In there is the file chrome/content/overlay.js
Replace the overlay.js with my version on http://pastebin.com/XRVxJdey

I hope this helps somebody!

Default Answered on February 26, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.