-1

I am new to selenium and I am facing issue with passing through authentication popup in chrome and firefox. Could anyone suggest me the best way to handle it.

I have tried providing credentials in the URL, however as credentials are asked every page that gets loaded, its getting harder and at times it doesnt work also.

  • possible duplicate of [How to handle authentication popup with Selenium Webdriver](http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver) – Mark Rotteveel May 14 '15 at 08:03
  • The answer to this questions is already mentioned ... http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver Hope this helps . – Girish May 14 '15 at 00:21

1 Answers1

0

The following Robot implementation does the following things when authentication dialog opens:

  1. It will paste UserName in argument on Username field because control is by default there
  2. Then It will Press Tab
  3. After that it will paste password in password field
  4. Again it will press TAB
  5. At last it will HIT enter

Solution in JAVA:

//Call this function and provide UserName and password 
public void authenticate(String password,String Uname) throws AWTException, InterruptedException
{
    Thread.sleep(5000);
    Robot rb=new Robot();       

    StringSelection stringSelection = new StringSelection(Uname);
    //Copy Path on Clipboard
    Toolkit.getDefaultToolkit().getSystemClipboard()
    .setContents(stringSelection, null);
    //Paste Clipboard Data
    rb.keyPress(KeyEvent.VK_CONTROL);
    rb.keyPress(KeyEvent.VK_V);
    rb.keyRelease(KeyEvent.VK_V);
    rb.keyRelease(KeyEvent.VK_CONTROL);
    rb.keyPress(KeyEvent.VK_TAB);
    rb.keyRelease(KeyEvent.VK_TAB);
    stringSelection = new StringSelection(password);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
    rb.keyPress(KeyEvent.VK_CONTROL);
    rb.keyPress(KeyEvent.VK_V);
    rb.keyRelease(KeyEvent.VK_V);
    rb.keyRelease(KeyEvent.VK_CONTROL);
    rb.keyPress(KeyEvent.VK_TAB);
    rb.keyRelease(KeyEvent.VK_TAB);
    rb.keyPress(KeyEvent.VK_ENTER);
    rb.keyRelease(KeyEvent.VK_ENTER);   

}
Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99
fahad
  • 389
  • 2
  • 12