2

I am using Selenium to simulate a user to automate some legacy software. The software works only with IE6 (I'm using IE11 in compatibility mode) and is a bit crap.

There is a point in the software where the Windows Security dialog appears. This requires credentials before the user/simulator can proceed.

I'm using IAlert.SetAuthenticationCredentials to try and populate the dialog but this doesn't seem to work. To move on from this, I can enter the details manually, but then Selenium seems to thing the main browser window has been closed:

Currently focused window has been closed.

The WindowHandles collection at this point is empty, but the browser window is still open, and has rendered the correct page.

What's going on here?

Screenshot

UPDATE

The answers provided are suggestions on how to handle the dialog. I'm wondering why Selenium thinks the browser window is closed when in fact it is still there.

Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
  • Can you blindly use something like SendKeys? I don't think you'll be able to target that security window, just like you can't target the UAC interface :/ – Davesoft Jul 05 '18 at 13:17

2 Answers2

2

It is not possible to interract with native windows via selenium. The way to deal with your issue is for example to use analogue of Robot in Java. Since you are using C# there is a simulator here https://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library.

Example code would be like following:

// Simulate (Ctrl + C) shortcut, which is copy for most applications
KeyboardSimulator.SimulateStandardShortcut(StandardShortcut.Copy);

// This does the same as above
KeyboardSimulator.KeyDown(Keys.Control);
KeyboardSimulator.KeyPress(Keys.C);
KeyboardSimulator.KeyUp(Keys.Control);

There are also Mouse simulators, so with this framework it will be possible to enter the required values in window and accept it.

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
1

Try to switch to that alert by,

var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("Username", "Pwd");
alert.Accept();

I have tested it and it works for IE11, selenium v3.1.0

Ref: https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_IAlert_SetAuthenticationCredentials.htm

Suggesstion 1-Go to internet explorer settings->security settings-> user authentication-> select automatic login with current username and password.enter image description here

Suggesstion 2- if your application has access to it's API, then login via API, get the authentication token and set the auth.token in browser cookie.

Magesh
  • 308
  • 1
  • 4
  • 18
  • thanks for the answer. Regarding solution 2, there is no API, hence the use of Selenium. There's also no login page, so requires the auth credentials. I understand there used to be able to do this in the url like `https://{username:password}:domain.com` but it's deprecated. – Paul Fleming Jul 05 '18 at 15:03
  • Regarding solution 1, the Windows user is not the user for this application. – Paul Fleming Jul 05 '18 at 15:04
  • Did you try this: https://Aladdin:OpenSesame@www.example.com/index.html where Aladdin is username and OpenSesame is password? – Sergiy Konoplyaniy Jul 05 '18 at 18:44
  • @SergiyKonoplyaniy Yes, it's deprecated and does not work. That's what I meant in my previous comment, forgive the incorrect syntax. – Paul Fleming Jul 06 '18 at 07:56