Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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
hey above solution is not working for me. Any suggestion please. –  user4709 Jan 21 '13 at 17:13
So many answers and none of them accepted? –  dzieciou Jan 21 '13 at 17:21

6 Answers 6

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: support.microsoft.com/kb/834489 –  dzieciou May 17 '14 at 17:07

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

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

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.