1

I am trying to Automate a login scenario of my project. After Hitting the URL a POPUP Authentication window comes even before the page loads. If we not pass that window we can't see the home page.

the problem is once the pop-up comes i can't inspect the element using firebug,its not letting me to click anywhere else.

i tries to handle the window but still the control is not going to the username and password text box. i tried windowhandle,robot class but not working. Please anybody can help??

here is the piece of code:-

Set<String> handles = driver.getWindowHandles(); // get all window handles
        System.out.println(handles.size());
        Iterator<String> iterator = handles.iterator();
        while (iterator.hasNext()){
            subWindowHandler = iterator.next();
        }
        driver.switchTo().window(subWindowHandler);
also the robot class:-

 Robot rb = new Robot();

                //Enter user name by ctrl-v
                StringSelection username = new StringSelection("myusername");
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(username, null);  
                Thread.sleep(2000);
river.switchTo().window(mainHandle);
                rb.keyPress(KeyEvent.VK_A);
                    rb.keyRelease(KeyEvent.VK_A);
                    rb.keyPress(KeyEvent.VK_M);
                    rb.keyRelease(KeyEvent.VK_M);
                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 pass = new StringSelection("password");
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(pass, 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);

                //wait
                Thread.sleep(5000);
Coolguy
  • 11
  • 3

2 Answers2

0

Its not possible to automate the browser based authentication using Selenium.

  • If your authentication is http based then try opening the url using format - http://username:password@example.com/ instead of example.com.

  • If at all you still want to automate it then use third party plugins like AutoIt to accomplish it which works along with Selenium. AutoIt is used to automate windows based desktop applications including browsers. Here are few links that you can refer to -

  • Also you can use plugins for firefox which authenticates the popups automatically, when you open the url. But this is a manual setup and you have to perform authentication once so that the plugin remembers it. Here's one of them.

Hope this helps.

Community
  • 1
  • 1
giri-sh
  • 6,934
  • 2
  • 25
  • 50
  • Hello Girish, the 1st option is not working i tried,before page loads that authentication pop-up comes. 2ndly how can we use AutoIT with Selenium Webdriver to automate that can u plzz describe. – Coolguy Sep 11 '15 at 10:14
  • That's a whole big process. Updated answer with few links that can help you with your automation. – giri-sh Sep 11 '15 at 10:34
0

You can do one thing. you can try it.

If we press ESC button then application stop processing many times.

after clicking on event use this below code:-

Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);

above code will press ESC for you. Now you can get the time to find the element.

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • Hi Shubham, i am not able to inspect element on that authentication pop-up. it askes first to give input on that pop-up. – Coolguy Sep 11 '15 at 10:17