4

Selenium Webdriver based test in C# must login with windows authentication.

I have tried a couple of approaches:

  _Driver.SwitchTo().Alert();
  _Driver.FindElement(By.Id("UserName")).SendKeys("LynnTest");
  _Driver.FindElement(By.Id("Password")).SendKeys("Welcome1!");
  _Driver.SwitchTo().Alert().Accept();
  _Driver.SwitchTo().DefaultContent();

and

  IAlert alert = _Driver.SwitchTo().Alert();
  alert.SendKeys("LynnTest\\t");
  alert.SendKeys("Welcome1!");
  _Driver.SwitchTo().Alert().Accept();
  _Driver.SwitchTo().DefaultContent();

Neither one is successful. I don't get the windows authentication dialog on my local system so I can't view the source to determine how to locate the username and password with the Selenium By method.

I believe the windows authentication dialog is provided by the browser, but I haven't found any source for the dialog.

Using Selenium (not AutoIt or other similar tools) how do I pass a username and password into the windows authentication dialog? The solution must be based on Selenium code, not add-ins, I have no access to the browsers as the are in the cloud.

Note: passing the username and password in the URL does not work, as I understand because the dialog is not generated by html on the page.

lynnjwalker
  • 741
  • 5
  • 11
  • 25
  • 1
    Read through [this](http://www.seleniumframework.com/intermediate-tutorial/authentication-pop-up/) – Saifur May 15 '15 at 01:43
  • If you are authenticate with a local account/domain account, I have a work around that worked. https://stackoverflow.com/questions/28045870/how-can-i-run-internet-explorer-selenium-tests-as-a-specific-domain-user/33666642#33666642 – Steven Nov 27 '17 at 22:54
  • @Saifur; that link is broken. – batpox Oct 17 '18 at 17:52

3 Answers3

5

You can NOT auth through this window with Selenium. Because of this is not browser window, but OS's authentication popup. Selenium have no ability to work with other processes except browsers.

But you can auth WITHOUT getting this window.

There is 2 ways to miss it:

  1. Change URL with authentication to: http://user:password@www.yourserveradress.com . This will work in part of situations and will authenticate you to needed service. In another case you can use way 2. [too old way, doesnt work now]

  2. You need to create a new profile in browser, pass authentication to needed service and remember password/authentication. And, ofc, use created browser profile in your tests.

    2.1. In case of service have short cookies life time, you can use "AutoAuth" plugin for your browser additionally in your profile from step 2.

upd: as I know there is some new way for selenium 3.0, you need to search more. This is too old answer. please ping me if you will wind better way.


  1. You can write own realization of login through the login popup with "White" framework. On needed step you can check all shown OS's windows for "correct" title. And in case of such title exist, get window's handle. And to do login using "White".

  2. You can use the following project https://github.com/ukushu/DialogCapabilities as sample and write your own realisation without using "White" framework.

Andrew_STOP_RU_WAR_IN_UA
  • 9,318
  • 5
  • 65
  • 101
0

When passing credentials through url is not working, you can do this by is using an external software "AutoIt V3" This works well with the windows authentication.

-1

In the end I used a workaround, navigating first to the authentication page, authenticating and then redirecting to the page to be tested as an authenticated user. This approach uses pages internal authentication page which can be scripted to.

lynnjwalker
  • 741
  • 5
  • 11
  • 25
  • 2
    You put out the code that did not work in your question, but provided none for your answer. Not very helpful. – batpox Oct 17 '18 at 17:51