Handling Window Authentication Pop-up on IE browser without using AutoIt.

5,098 views
Skip to first unread message

sushant umbarkar

unread,
Apr 20, 2015, 12:15:38 PM4/20/15
to seleniu...@googlegroups.com
Hi,

Please help me to handle Window Authentication Pop-Up  on IE browser. 
Due to some reasons I can not use AutoIT/Sikuli.

I tried few workarounds:
1. Passing username/password in URL but this does not work for IE.
2. Using Robot class: This is also not working.

Please suggest.

Panikera Raj

unread,
Apr 21, 2015, 7:43:58 AM4/21/15
to selenium-users
Sushant,

Have you tried this : 

WebDriver driver = new FirefoxDriver();

Regards,
Panikera


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/88910d95-7c80-4d06-b5f1-4ebf5977cb9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

manohar manohar

unread,
Apr 21, 2015, 10:43:22 AM4/21/15
to seleniu...@googlegroups.com

Using robot class you can handle...thing which u need to do is put the page load time before u invoke url and apply try catch for that block...once u got the exception u will be going into exception block ...ther use robot class

tulsi.tester

unread,
Apr 21, 2015, 11:51:47 PM4/21/15
to seleniu...@googlegroups.com
Hi Sushanth,

Using robot class with a little tweaking you can achieve this. Here you go. If it is not working try by increasing the sleep time. The only criteria is that the browser should be in focus.


public class LocalHttpAuthentication {

public static void main(String[] args) throws AWTException, InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
Robot robot;
try{
System.out.println("Entered try");
driver.findElement(By.id("displayImage")).click();
driver.switchTo().window("Authentication Window");
}catch( NoSuchWindowException e){
System.out.println("entered catch");
Thread.sleep(2000);
robot = new Robot();
robot = new Robot();
setClipboardData("httpwatch");
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.delay(5000);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
setClipboardData("123455678");
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.delay(5000);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
System.out.println("S3");
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
}
public static void  setClipboardData(String str){
StringSelection ss = new StringSelection(str);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
System.out.println("done");

VS

unread,
Jul 2, 2015, 3:06:58 AM7/2/15
to seleniu...@googlegroups.com
Hi Tulsi,

I  m trying to use the code you've written above.
But the difference is I am getting authentication pop up when i'm opening the URL.
So my test doesn't move at all from openurl() statement.

When i open the url, authentication window popsup and stays there forever. Test shows no exception and hanging.

Mukesh otwani

unread,
Jul 2, 2015, 10:00:25 PM7/2/15
to seleniu...@googlegroups.com
Hi VS,


I also was facing the same issue. Try below method

http://username:password@restoftheurl

for more info visit - Handle Authentication Window

tulsi.tester

unread,
Jul 3, 2015, 12:56:16 AM7/3/15
to seleniu...@googlegroups.com
Hi,

Then try to put the driver.get method in try block and keep the Robot code in the catch block and give a try. 


On Thursday, July 2, 2015 at 12:36:58 PM UTC+5:30, VS wrote:

Gouse Basha

unread,
Jul 3, 2015, 2:15:37 AM7/3/15
to seleniu...@googlegroups.com
HI,
Selenium cannot handle windows pop or wont work at all , like windows authentication , i had same requirement for my project to automate when i hit the url i used to get windows pop.
To handle such situation you need to implement java thread concept , in first thread invoke selenium and in second thread autoit method which can enter username and password and click enter.
This will solve your isssue

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards,
Basha
9538029173

VS

unread,
Aug 24, 2015, 10:21:48 AM8/24/15
to Selenium Users
Does Robot framework work when I run my tests in VmWare machine where i don't keep it focused.
Will it enter the data in the authentication window in vmware machine?

VS

unread,
Aug 24, 2015, 10:27:52 AM8/24/15
to Selenium Users
I tried using autoit script for entering data in authentication window/
When i run in local machine, it is stable.
But i have to run my tests in vmware machine which i don't keep focused always.
In Vm , the user/pwd is entered in authentication pop up. But it is not stable at all.
I have to clear cookies each time i login(my test requirement).

Here is my autoit script.

#include <Constants.au3>
AutoItSetOption("WinTitleMatchMode","2")
WinWait("Authentication Required","","10")
$title = WinGetTitle("Authentication Required") ; retrives whole window title
$UN=WinGetText($title,"User Name:")
ControlSend($title,"",$UN,"user");Sets Username
Sleep(2000);
$PWD=WinGetText($title,"Password:")
ControlSend ( $title, "", "", "{TAB}" )
Sleep(2000);
ControlSend($title,"",$PWD,"automation");Sets PWD
ControlSend ( $title, "", "", "{ENTER}" )

Kaleem Uddin Mohammed Abdul

unread,
Aug 25, 2015, 12:43:50 AM8/25/15
to Selenium Users
The AUTOIT code is not stable because you are not activating the window before doing any action.
Something like  Autoit.WinActivate(Constants.MozillaModalWindowName);


On Monday, April 20, 2015 at 9:45:38 PM UTC+5:30, sushant umbarkar wrote:
Message has been deleted

Pankaj Dhapola

unread,
Jan 23, 2016, 11:18:11 AM1/23/16
to Selenium Users
Hi All,

Is there any possibility we can create a dot net based console application exe, which can leverage the use of CUIT classes Like WinEdit, WinButton and WinWindow. This exe will take args[] as UID and PWD and handle the authentication window?

Has anyone tried this?

Thanks
PD

On Monday, April 20, 2015 at 9:45:38 PM UTC+5:30, sushant umbarkar wrote:

vishal srivastava

unread,
Jan 23, 2016, 12:47:41 PM1/23/16
to Selenium Users
You can use browsermob proxy in your code

vishal srivastava

unread,
Jan 23, 2016, 12:48:01 PM1/23/16
to Selenium Users

vishal srivastava

unread,
Jan 23, 2016, 12:48:02 PM1/23/16
to Selenium Users

Krishnan Mahadevan

unread,
Jan 23, 2016, 9:49:00 PM1/23/16
to Selenium Users
Pankaj,
I believe AutoIT essentially is doing the same thing as what you are proposing via your exe. 
Answer to your question is "Yes", you can very well do that. Give it a try and share the solution with other folks as well.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Sat, Jan 23, 2016 at 9:46 PM, Pankaj Dhapola <dhapol...@gmail.com> wrote:
Hi All,

Is their any possibility we can create a dot net based console application exe, which can leverage the use of CUIT classes Like WinEdit, WinButton and WinWindow. This exe will take args[] as UID and PWD and handle the authentication window?

Has anyone tried this?

Thanks
PD

On Monday, April 20, 2015 at 9:45:38 PM UTC+5:30, sushant umbarkar wrote:

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Serguei Kouzmine

unread,
Feb 4, 2016, 10:32:03 PM2/4/16
to Selenium Users


Pankaj Dhapola ,

I have such tool developed via c# with somewhat heavy win32 p/invoke code, and can help you with your authentication

the screenshot manages to access file name and "ok" button(the button text is changed) - to work with your dialog i need to have access to your scenario, to  tailor the tool code to find your particular window class chain.


I own the code so it will not be a problem , but i do not have IIS / Windows domain integration to try it upfront.

Let me know if you are interested in pursuing this project

or interested in srufying the source yourself on my github

Thanks,
Serguei Kouzmine

Pankaj Dhapola

unread,
Feb 6, 2016, 12:44:26 AM2/6/16
to Selenium Users
Hey Serguei,

Thank you very much for the kind help. I can't share you the application URL's as it is not available in public domain.
Would you be able to share the code, I shall make a sense out of it for my issue.

Basically I am looking for an .exe (C# console application) file which will take up UID, PWD and action (cancel/ok) as argument to fill in  Authentication Popup.

Thanks
PD

Serguei Kouzmine

unread,
Feb 8, 2016, 9:15:22 PM2/8/16
to Selenium Users
Hello Sushant

Be my guest -  the project is available on github,

https://github.com/sergueik/powershell_selenium/tree/master/csharp/explorer_dialog_automator/


ConfigureApp.cs
ConfigureApp.designer.cs
ConfigureApp.resx
ConsoleProgram.cs
ConsoleProgram2.cs
CustomIntervalPicker.cs
EnumReport.cs
NativeMethods.cs
Program.csproj
Properties
SystemTrayApp.cs
busy_icon.ico
idle_icon.ico
main_icon.ico
packages.config

To detect the dialog in question, fork, review and start modifying from
https://github.com/sergueik/powershell_selenium/blob/master/csharp/explorer_dialog_automator/Program/EnumReport.cs#L136
https://github.com/sergueik/powershell_selenium/blob/master/csharp/explorer_dialog_automator/Program/EnumReport.cs#L202

Note : explorer_dialog_automator is kind of a trimmed down verison of some bigger scratch project which may have unrelated code which you can safely remove. Currently explorer_dialog_automator is heavily tailored to deal with file dialogs (). If you can create a skeleton web app with the kind of authentication you need , it may help me to help you

Note: I plan to resurrect that same project soon for the authentication needs myself


Serguei Kouzmine

On Monday, April 20, 2015 at 12:15:38 PM UTC-4, sushant umbarkar wrote:

Jim Evans

unread,
Feb 9, 2016, 6:40:53 AM2/9/16
to Selenium Users
I swore I was done with this list, but I can't abide this any longer. Why do people insist on reinventing things WebDriver already gives you? There should be very, very little need *ever* to work with system dialogs in WebDriver[1]. If you find you think you need to, it's likely You're Doing It Wrong. Using the .NET bindings with IE, you can do this:

driver.Url = authenticationPage;
IAlert alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("User", "password");
alert.Accept();

There's no need for AutoIt, someone else's open source dialog handler (my own is available at https://github.com/jimevans/BrowserDialogHandler), or any other project that people might suggest.

Caveats to using this: While it's implemented as part of the WebDriver JSON wire protocol, it hasn't been standardized by the W3C yet. Furthermore, only the IE driver has implemented the feature at present, but remember that you can pass user name and password information in the URL for other browsers.

[1] Yes, this includes file dialogs. Uploading files can be done with SendKeys; clicking on the browse button to select a file to upload is a misunderstanding of the API. Selecting a download location for a file is usually a sign that you've not thought through what you're attempting to test.

Serguei Kouzmine

unread,
Feb 9, 2016, 11:38:37 AM2/9/16
to Selenium Users
Hello Jim

Thanks for sharing your procjet link. Regarding mine, please note it is derived on work which I did over  10  years ago. There was little SwitchTo().Alert support  back then. Regarding the Panka's case possibly they are running IE8 who or some other custom situation where  drier provided support for Windows authentication alert is limited who knows,

In order to help I really have to set up IIS with windows authentication on a Windows vm.
Can you help ?
Thanks in advance

Serguei Kouzmine

On Monday, April 20, 2015 at 12:15:38 PM UTC-4, sushant umbarkar wrote:

Pankaj Dhapola

unread,
Mar 11, 2016, 12:11:35 PM3/11/16
to Selenium Users
Hey All,

I was able to resolve the issue w.r.t Authentication dialog using user32.dll function calls.
This seems to be most resilient and robust solution.

Below is the chunk of raw code. Please customise as per your need



 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Diagnostics;

using System.Runtime.InteropServices;

using System.Collections;

 

namespace PopupHandler

{

 

    class Program

    {

        private const int WM_SETTEXT = 0x000C;

        public const int WM_SYSCOMMAND = 0x0112;

        public const int SC_CLOSE = 0xF060;

        public const int BM_CLICK = 0x00F5;

        public const int EM_SETPASSWORDCHAR = 0X00CC;

 

        [DllImport("user32.dll")]

        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("User32.dll")]

        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindows);

        [DllImport("User32.dll")]

        private static extern Int32 SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, StringBuilder lParam);

        [DllImport("user32.dll")]

        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

 

        private void HandlePopUp(string browser, string executionmode, string uid, string pwd)

        {

            

 

 

            if (browser.Equals("ie", StringComparison.InvariantCultureIgnoreCase))

            {

                if (executionmode.Equals("cancel", StringComparison.InvariantCultureIgnoreCase))

                {

                    // retrieve Windows Security main window handle

                    IntPtr hWnd = FindWindow("#32770", "Windows Security");

                    int iterateForSecurityPopup = 0;

                    for (iterateForSecurityPopup = 0; iterateForSecurityPopup < 20; iterateForSecurityPopup++)

                    {

                        hWnd = FindWindow("#32770", "Windows Security");

                        if (!hWnd.Equals(IntPtr.Zero))

                        {

 

                            SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);

                            Environment.Exit(0);

                        }

                        System.Threading.Thread.Sleep(1000);

                    }

                    if (hWnd.Equals(IntPtr.Zero)) {

                        Console.WriteLine("Dialog with title Security Popup not found");

                    }

                }

                else (executionmode.Equals("ok", StringComparison.InvariantCultureIgnoreCase))

                {

                    string[] data = { uid, pwd };

                    // retrieve Windows Security main window handle

                    IntPtr hWnd = FindWindow("#32770", "Windows Security");

                    int iterateForSecurityPopup = 0;

                    IntPtr duihWnd;

 

                    for (iterateForSecurityPopup = 0; iterateForSecurityPopup < 25; iterateForSecurityPopup++)

                    {

                        hWnd = FindWindow("#32770", "Windows Security");

                        if (!hWnd.Equals(IntPtr.Zero))

                        {

                            // Get DirectUIHandle

                            duihWnd = FindWindowEx(hWnd, IntPtr.Zero, "DirectUIHWND", "");

                            if (!duihWnd.Equals(IntPtr.Zero))

                            {

                                ArrayList childs = GetAllChildrenWindowHandles(duihWnd, 15);

                                int i = 0;

                                int j = 0;

                                while (i <= childs.Count)

                                {

                                    IntPtr edithWnd = FindWindowEx((IntPtr)childs[i], IntPtr.Zero, "Edit", "");

                                    if (!edithWnd.Equals(IntPtr.Zero))

                                    {

                                        // send WM_SETTEXT message to control

                                        SendMessage(edithWnd, WM_SETTEXT, IntPtr.Zero, new StringBuilder(data[j]));

                                        j++;

                                        if (j == 2) { break; }

                                    }

                                    i++;

                                }

 

                                i = 0;

                                while (i <= childs.Count)

                                {

                                    //Click on ok

                                    IntPtr btnOkhWnd = FindWindowEx((IntPtr)childs[i], IntPtr.Zero, "Button", "OK");

 

                                    if (!btnOkhWnd.Equals(IntPtr.Zero))

                                    {

                                        SendMessage(btnOkhWnd, BM_CLICK, 0, 0);

                                        break;

                                    }

                                    i++;

                                }

                            }

                        }

 

                       System.Threading.Thread.Sleep(750);

                    }

 

                    if (hWnd.Equals(IntPtr.Zero))

                    {

                        Console.WriteLine("Dialog Handle not present");

                    }

 

                }


           

            }


 

        }

 

        static ArrayList GetAllChildrenWindowHandles(IntPtr hParent, int maxCount)

        {

            ArrayList result = new ArrayList();

            int ct = 0;

            IntPtr prevChild = IntPtr.Zero;

            IntPtr currChild = IntPtr.Zero;

            while (true && ct < maxCount)

            {

                currChild = FindWindowEx(hParent, prevChild, null, null);

                if (currChild == IntPtr.Zero)

                {

                    int errorCode = Marshal.GetLastWin32Error();

                    break;

                }

                result.Add(currChild);

                prevChild = currChild;

                ++ct;

            }

            return result;

        }


        static void Main(string[] args)

        {

 

            string browser = args[0];

            string mode = args[1];

            string uid = "";

            string pwd = "";

 

                uid = args[2];

                pwd = args[3];

 

            new Program().HandlePopUp(browser, mode, uid, pwd);

 

 

        }

    }

}


The command line argument would be

ie ok uid pwd

i.e. cancel


Thanks

PD


On Monday, April 20, 2015 at 9:45:38 PM UTC+5:30, sushant umbarkar wrote:

Rupesh Patil

unread,
Mar 13, 2016, 10:38:33 AM3/13/16
to Selenium Users
Save bellow script as .au3 then create .exe file.

WinWaitActive("Windows Security","","20")
if(WinExists("Windows Security")) Then
Send("Selenium_user{TAB}")
Send("Selenium_Pass{ENTER}")
EndIf

then call this ,exe from java code.

David

unread,
Mar 13, 2016, 3:12:24 PM3/13/16
to Selenium Users
Jim, is that IE driver feature available in other language bindings as well or just the .NET bindings? I wasn't aware of this new feature. And you mention it's part of WebDriver JSON wire protocol (but not standardized yet), is that documented in the protocol docs or something we'll have to reverse engineer again to figure out (say to support it in 3rd party unofficial language bindings)?

Serguei Kouzmine

unread,
Mar 13, 2016, 5:27:09 PM3/13/16
to Selenium Users
Hello David

What particular language were you interested to see the native win32  api be wrapped ? This is what Jim's project and my project are using...
thanks,

Serguei Kouzmine

Ashton Fernandes

unread,
Mar 13, 2016, 8:06:28 PM3/13/16
to Selenium Users
Hello,

I was having the same issue and finally got it fixed.
Try the following code and it should work.
You will have to import the libraries along the way.

        driver.navigate().to("http://sitename");
        StringSelection selection = new StringSelection("username");
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(selection, selection);
        Thread.sleep(2000);
        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(1000);
        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);

David

unread,
Mar 14, 2016, 7:53:17 PM3/14/16
to Selenium Users
Serguei,

I was referring to the built in IE driver support that Jim mentioned. If I'm not mistaken, Jim's code snippet in this thread referred to native support in IE driver with .NET/C#, no need for Jim's separate 3rd party project nor yours. In which case, my question was, whether that built-in feature was .NET only or available to the other languages using IE driver. Asking such as I recall in the past, certain features were only available in Java, but not others, etc. at least before it got implemented in the rest of the languages (remote file uploads over Selenium Grid being one example).

Serguei Kouzmine

unread,
Mar 14, 2016, 10:23:27 PM3/14/16
to Selenium Users
Hello David,

You can study the source 

and find all the implemented methods

```
int Alert::Accept() {
int Alert::Dismiss() {
int Alert::SendKeys(const std::string& keys) {
int Alert::SetUserName(const std::string& username) {
int Alert::SetPassword(const std::string& password) {
int Alert::SendKeysInternal(const std::string& keys,
std::string Alert::GetText() {
std::string Alert::GetStandardDialogText() {
std::string Alert::GetDirectUIDialogText() {
int Alert::ClickAlertButton(DialogButtonInfo button_info) {
bool Alert::IsOKButton(HWND button_handle) {
bool Alert::IsCancelButton(HWND button_handle) {
bool Alert::IsSimpleEdit(HWND edit_handle) {
bool Alert::IsPasswordEdit(HWND edit_handle) {
BOOL CALLBACK Alert::FindDialogButton(HWND hwnd, LPARAM arg) {
BOOL CALLBACK Alert::FindTextBox(HWND hwnd, LPARAM arg) {
BOOL CALLBACK Alert::FindTextLabel(HWND hwnd, LPARAM arg) {
BOOL CALLBACK Alert::FindDirectUIChild(HWND hwnd, LPARAM arg){
BOOL CALLBACK Alert::FindTextBoxes(HWND hwnd, LPARAM arg) {
```
Thanks,

Serguei Kouzmine

Krishnan Mahadevan

unread,
Mar 14, 2016, 10:47:43 PM3/14/16
to Selenium Users
Serguei,

I thought that the cpp part of IEDriverServer was only for the server component. You would still need the client bindings to basically implement the means to invoke it as well no ?

All said and done, I did find that there is an implementation with @Beta annotation

So am guessing it may perhaps work for IE, but not sure if its going to work for ChromeDriver and Firefox




Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Serguei Kouzmine

unread,
Mar 15, 2016, 10:18:26 PM3/15/16
to Selenium Users
Hello Krishnan

I think the native dialog layouts are very specific to browsers, and the Alert code is not portable.

Serguei Kouzmine
Reply all
Reply to author
Forward
0 new messages