We have eventually solved this issue by using the Windows Automation 3.0 API to pick up the dialogue box and handle the logging in. This was done as follows:
- Fire up an IE process and assign it to an AutomationElement
- You now have the ability to traverse through the child elements of the IEFrame, picking up the username and password Edit fields.
- Then send the username and password
Once the browser has been authenticated we then attach it to a WatiN IE browser object. The code follows below:
public static Browser LoginToBrowser(string UserName, string Password, string URL)
{
AutomationElement element = StartApplication("IEXPLORE.EXE", URL);
Thread.Sleep(2000);
string t = element.Current.ClassName.ToString();
Condition conditions = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
Condition List_condition = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
Condition Edit_condition = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
Condition button_conditions = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
AutomationElementCollection c = element.FindAll(TreeScope.Children, conditions);
foreach (AutomationElement child in c)
{
if (child.Current.ClassName.ToString() == "#32770")
{
//find the list
AutomationElementCollection lists = child.FindAll(TreeScope.Children, List_condition);
// find the buttons
AutomationElementCollection buttons = child.FindAll(TreeScope.Children, button_conditions);
foreach (AutomationElement list in lists)
{
if (list.Current.ClassName.ToString() == "UserTile")
{
AutomationElementCollection edits = list.FindAll(TreeScope.Children, Edit_condition);
foreach (AutomationElement edit in edits)
{
if (edit.Current.Name.Contains("User name"))
{
edit.SetFocus();
//send the user name
}
if (edit.Current.Name.Contains("Password"))
{
edit.SetFocus();
//send the password
}
}
}
}
foreach (AutomationElement button in buttons)
{
if (button.Current.AutomationId == "SubmitButton")
{
//click the button
break;
}
}
}
}
return IE.AttachToIE(Find.By("hwnd", element.Current.NativeWindowHandle.ToString()), 30) ;
}
We did use a tool called UI Spy to examine the Windows UI. If you run it against XP and Win7 you can clearly see how the structure of the Windows Security dialogue box has changed between the 2 OS's.