If your confirmation dialog doesn't work in IE9, try the following solution
(Visual Studio 2010, Windows7, NetFramework 4.0, Internet explorer 9)
First you must add links to UIAutomationClient and UIAutomationTypes in your test project.
The following method extends the browser class.
public static void ConfirmDialogIE9(this Browser browser) { browser.ShowWindow(NativeMethods.WindowShowStyle.ShowMaximized); Thread.Sleep(2000); System.Windows.Automation.TreeWalker trw = new System.Windows.Automation.TreeWalker(System.Windows.Automation.Condition.TrueCondition); System.Windows.Automation.AutomationElement mainWindow = trw.GetParent(System.Windows.Automation.AutomationElement.FromHandle(browser.hWnd)); System.Windows.Automation.AutomationElementCollection main = mainWindow.FindAll(System.Windows.Automation.TreeScope.Children , System.Windows.Automation.Condition.TrueCondition); foreach (System.Windows.Automation.AutomationElement element in main) { if (element.Current.Name.Equals("VIIS - Windows Internet Explorer") && element.Current.LocalizedControlType == "pane") { System.Windows.Automation.AutomationElement DialogBox = trw.GetFirstChild(element); DialogBox.SetFocus(); System.Windows.Automation.InvokePattern clickOk = (System.Windows.Automation.InvokePattern) DialogBox.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition)[0].GetCurrentPattern(System.Windows.Automation.AutomationPattern.LookupById(10000)); clickOk.Invoke(); Thread.Sleep(1000); break; } }
source share