0

When I launch a website from Eclipse (selenium) it pops up a authentication box as below:

enter image description here

Here I am unable to enter Username and password, here are the things I tried:
1) Switching of Handle to pop up and identifying Xpath
2) Sending Username and Password in the URL (How to handle login pop up window using Selenium WebDriver?)
3) Sikuli (but requires image capture when executed in different system)
4) Using Robot function

        Robot rb = new Robot();
        StringSelection username = new StringSelection("XXXXX");
        System.out.println("Entering username");
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(username, null);            
        rb.keyPress(KeyEvent.VK_CONTROL);
        rb.keyPress(KeyEvent.VK_V);
        rb.keyRelease(KeyEvent.VK_V);
        rb.keyRelease(KeyEvent.VK_CONTROL);

        //tab to password entry field
        rb.keyPress(KeyEvent.VK_TAB);
        rb.keyRelease(KeyEvent.VK_TAB);
        Thread.sleep(2000);

        //Enter password by ctrl-v
        StringSelection pwd = new StringSelection("YYYYYYY");
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(pwd, null);
        rb.keyPress(KeyEvent.VK_CONTROL);
        rb.keyPress(KeyEvent.VK_V);
        rb.keyRelease(KeyEvent.VK_V);
        rb.keyRelease(KeyEvent.VK_CONTROL);

        //press enter
        rb.keyPress(KeyEvent.VK_ENTER);
        rb.keyRelease(KeyEvent.VK_ENTER);

None of the above worked till now, just after reaching the website (driver.get(URL)) the control does not seem to come back to eclipse

Community
  • 1
  • 1
Vinod
  • 376
  • 2
  • 11
  • 34
  • Update: Tried with AutoIT as well, not working – Vinod Jun 09 '15 at 11:21
  • Did you test the autoIT script first? – Vikas Ojha Jun 09 '15 at 14:09
  • @VikasNehaOjha: Yes, I called the script after/before launching the url with some wait time, however the script does not run, i added a print statement in eclipse between launch url and call AutoIt script, this never gets executed. – Vinod Jun 10 '15 at 03:20

2 Answers2

0

Use AutoIT scripts to fill that windows. That is the only way to elegantly handle this issue in Windows with Selenium. Check Handle Windows based Authentication Pop Up in Selenium using AutoIt at http://www.toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/

Vikas Ojha
  • 6,742
  • 6
  • 22
  • 35
  • Will someone care to answer the reason for downvoting this answer? I am using it for years and know how to do it. – Vikas Ojha Jun 09 '15 at 13:17
0

The below code should work, it can be refactored :)

driver.navigate().to("url");
StringSelection selection = new StringSelection("username");
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
Thread.sleep(5000);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(2000);
selection = new StringSelection("password");
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);  
robot.keyRelease(KeyEvent.VK_ENTER);