13

the popup window is only happening if I use the Fire Fox browser otherwise, is there a way to fix this problem? I have to enter userid/password every time the i use FF as my browser.

currently, I am entering every time i run my test which is very painful but looking to make it more automated....

I have goggled and found two links here and here but no avail

enter image description here

Community
  • 1
  • 1
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • i tried something like this - Use the approach where you send username and password in URL Request: `http://username:password@the-site.com` - but did not work either... still asking the username/password – Nick Kahn Aug 28 '12 at 02:26
  • Which browser is this? case the URL format is not supported by all browsers. If it does not work with webdriver than it should also not work for you manually. – Ashwin Prabhu Aug 28 '12 at 05:48
  • I had the same issue (with FF too). It works if you enter the URL manually, but not if you use the webdriver. I haven't found a solution though :( – Stilltorik Aug 28 '12 at 09:27
  • http://stackoverflow.com/questions/10395462/handling-browser-authentication-using-selenium
    This might help you
    – Harshavardhan Konakanchi Aug 28 '12 at 11:37
  • @Ashwin: I am using IE and its happening only with FireFox – Nick Kahn Aug 28 '12 at 13:44
  • @AbuHamzah Then I think the best and easiest way is to not do anything special and let browser prompt for username/password. You can use awt.Robot to fill in the details and hit enter easily. – Ashwin Prabhu Aug 29 '12 at 07:32

5 Answers5

7
http://username:password@xyz.com 

This worked for me (xyz.com being the site name)

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
sharad
  • 79
  • 1
  • 1
5

If this is a windows user account & password, then you need to enable the integrated windows login by setting

network.negotiate-auth.delegation-uris: MyIISServer.domain.com
network.automatic-ntlm-auth.trusted-uris: MyIISServer.domain.com
network.automatic-ntlm-auth.allow-proxies: True
network.negotiate-auth.allow-proxies: True

in the Firefox profile that WebDriver starts. Once you have the profile created and saved (run "Firefox -P" when no other instances are running to select a profile), you can do this in the code:

File profileDir = new File("C:/wherever/SeleniumFirefoxProfile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setEnableNativeEvents(true);
driver = new FirefoxDriver(profile);
VolleyJosh
  • 161
  • 1
  • 1
  • 13
  • i have enable the integrated windows login in firefox but when i run my test using firefox it prompts me to enter userid/password, any idea? – Nick Kahn Oct 10 '12 at 16:17
  • Can you normally get to the site with no login dialog presented? If so, can you do that manually using a Firefox session that WebDriver launched? If not, then you need to make sure that the profile you created is the one being loaded by WebDriver. By default it loads FireFox with the default empty profile. You need to use the profile manager (the -p option) to create and start a profile, then set the windows pass-through auth. Once that's done, move the profile to a folder and point webDriver at it with the code above. I also installed Firebug in that profile, so I could debug the page. – VolleyJosh Oct 10 '12 at 23:01
  • let me tell you what i have done so far, i folled the link you in your reply which is enable the itnegrated windows login and i have added the site name that i am trying to write test scripts for. answer to your question: we have internal web site that requires windows authentication so if I clear out all my cache and password from my machine and try to login then FireFox did propmet me to enter the userid/password and once i enter my credential and login to the site and will never ask me again unless if i chagne the password. so when i am testing the same site with firefox. – Nick Kahn Oct 10 '12 at 23:15
  • regardless, how many times i enter the credential it always ask me....can you show me the steps how to acheive what you have just said about? – Nick Kahn Oct 10 '12 at 23:15
  • Sounds like you have a site that is not using the windows login (your domain account and password), because you should never have to specify credentials once the feature is enabled (network.automatic-ntlm-auth.trusted-uris). Probably what you need to do is get that cached name/pass into your WebDriver launched Firefox instances profile. Are you able to confirm that WD is starting FireFox using your custom profile? If so then manually start FF with that profile, get to the login prompt, enter credentials & check the 'remember' box and then close FF. If WD uses that profile then it should work. – VolleyJosh Oct 11 '12 at 17:36
  • i haven't create the custom profile yet how will i go creating just by typing `firefox.exe -p` ? then after that what do i need to do? – Nick Kahn Oct 12 '12 at 16:17
  • See http://www.borngeek.com/firefox/profile-tutorial/ You need to do that, use that new profile to login to the page, then find the folder where that profile is stored, save it somewhere easy to find and then point WebDriver at it using the code above. – VolleyJosh Oct 12 '12 at 17:17
  • 1
    [link](http://stackoverflow.com/questions/5383958/how-do-i-rerun-selenium-2-0-webdriver-tests-on-the-same-browser) to a similar discussion here. – VolleyJosh Oct 17 '12 at 17:34
5

After spending hours reading I finally found the solution which works pretty well and I hope this will help others too. - Enjoy!!

First - follow this steps:

1) Open the FireFox browser
2) Type the following `about:config`
3) Look for `network.http.phishy-userpass-length` if you don't find then create a new Integer key 
Create a new Integer key (right-click->New->Integer): `network.http.phishy-userpass-length` with value `255`

Second: You need to create a Firefox driver with the following:

FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.http.phishy-userpass-length", 255);
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "YOUR HOST ADDRESS HERE");
_driver = new FirefoxDriver(profile);

let me know if you have any questions.

Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • not working for me. I am using proxy. If I do this, I am not able to use proxy. – roger_that Feb 20 '15 at 06:41
  • This solution worked for me in addition to doing http://username:password@xyz.com. Note that username and password should be URL encoded if it has special characters. – Kamal Joshi Dec 14 '16 at 19:57
0

I have had to handle these a few times, but my approach is using a script outside Selenium. Are you working on Windows?

Basically what you do is this:

1) Prior to loading the page, clicking the URL, etc that causes that dialog to appear:

-- Launch an asynchronous script to handle the login

2) Then load the page, click the link, etc

-- Selenium will block until your asynch script completes

The async script:

-- Sleep for a few seconds
-- Activate the dialog
-- Send the username
-- Send a TAB
-- Send the password
-- Send a TAB
-- Send the Enter Key

If you are working on windows, I can post sample scripts to handle this. I've done it with Java and C#, but I would guess that basically the same thing would work regardless of how you are writing your tests (unless you are strictly using the FF plugin, in which case this won't work).

Let me know if you'd like more details.

chrismead
  • 2,163
  • 3
  • 24
  • 36
  • 1
    I would be very interested in the sample C# script if you've still got it available. – B-K May 20 '13 at 05:05
0

You can use a FF plugin "autoauth". Download this plugin and create Firefox instance by the following way:

FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
File pluginAutoAuth = new File("D:\\autoauth-2.1-fx+fn.xpi");
firefoxProfile.addExtension(pluginAutoAuth);
driver = new FirefoxDriver(firefoxProfile);

I used "autoauth-2.1-fx+fn.xpi"

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176