Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am automating an application which contains browser level authentication.

When I open the application, the browser performs basic authentication, i.e. it prompts for a username and password. How can I handle this scenario using Selenium?

share|improve this question

instead of

share|improve this answer
Misha Akovantsev did the trick. I love simple solutions like this. If you have different environments (with/without password) you would have to use an "if" to handle this. Since the URL is already externalized, perfect solution. – Felipe Butcher Dec 29 '12 at 20:06
Hi @FelipeButcher - welcome to SQA! As you don't yet have the privs to add comments directly, I've taken the liberty of moving your answer to a comment on the post you were talking about, so that people can see it in the right place. – testerab Dec 30 '12 at 12:59
Awesome solution. The only disadvantage is that credentials will be logged on a server side as part of URL. But I believe this is minor security concern, as you probably already have those credentials harcoded in your test data and they are fake. – dzieciou May 17 '14 at 17:03
I tried this approach manually in IE and Chrome. And IE does not accept this URL syntax for security reasons: – dzieciou May 17 '14 at 17:07
I wasn't able to get passed the HTTP auth with the ChromeDriver. This doesn't always work with Selenium. It's driver dependent. – joël Apr 18 at 15:30

Here one method of handling, Create browser profile and check remind password. By calling the profile before the execution, It won't ask you the authentication next time onwards. Let me know if it doesn't work.

share|improve this answer
That may work with Firefox, does that work for IE or Chrome? Failed for me using the ChromeDriver. – joël Apr 18 at 15:32

Basic authentication isn't handled very well in Selenium, and to be honest, I'm not certain that it should be either (although it would be nice). The solution that I've been using is to create a script in autoIT or something similar that is able to access the authentication box. Essentially, create the script that looks for the authentication box, enter credentials, click OK or press Enter and then either end or kill this sub script.

It's dirty, not ideal, but it's the best solution that I've found so far that can work with multiple browsers.

share|improve this answer

It would be better if you provide some more info on what language/platform are you using, but, anyway…

Selenium is not really good on handling such windows, so

If you are using Java, then please look at Robot class

If you are using Ruby, C#, Java, then look at WatiR, WatiN, WatiJ. All this libraries can attach to the existing browser by it’s title and handle the pop-up dialogs. I am not saying about replacing Selenium with WatiN, but you can use this library of this specific purpose.

Also for .NET you can use Windows UI automation

And, of course, you can use AutoIt or AutoHotkey. The most simplest way is to compile the dialog handling code in to .exe file and run it with specific parameters when it is necessary.

share|improve this answer
Thanks for the response, iam using java (TestNG) with selenium and platform is windows machine firefox browser – saikrishna Mar 15 '12 at 8:36

Adding to Dmitry's and Lyndon's answer, you can also using Apple scripts if you are using a Mac machine. It is very efficient to handle such situations. Just need to run the scripts using java runtime class if you are using java.

share|improve this answer

I just got done working on a prototype project that is supposed to handle exactly this kind of situation. It is written in C#, so it currently only works for the .NET release of Selenium.

It utilizes BrowserMob, a popular open source proxy, to perform the authentication.

SeleniumBasicAuthWrapper Hope it helps! It is still a work in progress, but hopefully we'll get any kinks or defects ironed out in the near future.

share|improve this answer

Since this is one of the top hits on google ill provide the ruby solution if you cant use the http://username:password@url.

you can use system input but doing it on windows and on mac are different. Here is the solution on a mac:

You would have to detect if the test is running on windows or mac first and then do the corresponding.{
    @browser.get 'url';

    sleep (10)
    #replace these lines with the windows corresponding if on windows.
    %x(osascript -e 'tell application "System Events" to keystroke "username"')
    %x(osascript -e 'tell application "System Events" to keystroke tab')
    %x(osascript -e 'tell application "System Events" to keystroke "password"')
    %x(osascript -e 'tell application "System Events" to keystroke return')


Here is the windows solution:{
    @browser.get 'url'  

    sleep (5)
    wsh ='Wscript.Shell')
    wsh.AppActivate('browser') #fx. firefox
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.