When I open the application,it prompts for a username and password. How can I handle this scenario using Selenium java in INTERNET EXPLORER?

  • What is special about Internet Explorer in this scenario ? What about firefox say is that ok. chrome and safari? Feb 5, 2016 at 14:38
  • See also sqa.stackexchange.com/q/2755/8992 Feb 5, 2016 at 14:40
  • yeah i need to run the application in IE only, because application work much faster in IE only
    – Surya
    Feb 5, 2016 at 15:19
  • i'm automating the sanity check
    – Surya
    Feb 5, 2016 at 15:20
  • 2
    I realize this isn't SO, but showing what you've tried, what's working/not working, etc, are all still important for asking a good question . . .
    – ernie
    Feb 6, 2016 at 23:16

3 Answers 3


Selenium doesn't offers much help in handling browser level authentications. You can use java robot class to handle browser level authentication as shown below:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.io.IOException;

public static void browserLevelAuthentication() throws AWTException{
   // initialize the web driver and open the web page
      WebDriver _webDriver = new ChromeDriver();

  // create robot for keyboard operations      
      Robot rb = new Robot();

  // Enter user name in username field 
 StringSelection username = new StringSelection("testUser1");
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(username, null);            

  // press tab to move to password field

  //Enter password in password field
       StringSelection pwd = new StringSelection("testPassword");
       Toolkit.getDefaultToolkit().getSystemClipboard().setContents(pwd, null);

  //press enter

Other than java robot class, you can also use Autoit tool to handle authentication.

Or you have to pass the username password in URL like


Here <USERNAME> is username for that web application

, <PASSWORD> is password for above mentioned user

and <URL> is url of the web application

  • Thanks for your answer.. it works for me.. thanks a lot @ sarabjit
    – Surya
    Feb 21, 2016 at 9:01

You need to specify how the browser level authentication box is coming up for starters. Is it a JS pop up or is it a modal window. Depending on this, you can use corresponding methods from Selenium - driver.switch_to.alert or driver.switch_to.window() methods- these are in python, but you have corresponding methods in Java also.

Also, you can refer to this question, where it has been discussed in detail- though it is not IE specific.


Though you can use ROBOT class for this, but it highly recommended to avoid ROBOT class uses as much as you can.

If I understood correctly, your website has authentication, it prompts the user name and password. you do not require to do anything with selenium.

You have to add username and password in url for example, your url is


you have to write it in this way

driver.get("http://username:[email protected]")

This will bypass the authentication window.

INFO: This kind of authentication to websites are done, to avoid google ranking, no one will like to rank their testing or dev sites in google

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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