WatiN ie9 confirmation dialog not working

Possible duplicate:
Watin and IE9 - Cannot click ok

var dialogHandler = new WatiN.Core.DialogHandlers.ConfirmDialogHandler(); using (new WatiN.Core.DialogHandlers.UseDialogOnce(browser.DialogWatcher, dialogHandler)) { browser.Button(Find.ById("btnSave")).ClickNoWait(); dialogHandler.WaitUntilExists(); } 

it does not work on ie 9, javascript confirmation I already use the latest version 2.1

0
source share
4 answers
 ConfirmDialogHandler confirmHandler = new ConfirmDialogHandler(); using (new UseDialogOnce(browser.DialogWatcher, confirmHandler)) { confirmHandler.WaitUntilExists(); confirmHandler.CancelButton.Click(); } 

it works on ie7 but not 9 Answer DrunkenMonkey does not work.

WatiN-2.1.0.1196

0
source

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; } } 
0
source

My project has the following code:

 var cancel = browser.Link(Find.ByUrl(CANCEL_LINK)); var confirmDialog = new ConfirmDialogHandler(); using (new UseDialogOnce(browser.DialogWatcher, confirmDialog)) { cancel.ClickNoWait(); confirmDialog.WaitUntilExists(); confirmDialog.OKButton.Click(); browser.WaitForComplete(); } 

This works in IE9. Please note that this is WatiN v2.0.50727, but I do not see that this should affect the fact that you are using v2.1.

0
source

Watin has dialog handling methods. Try using the following methods:

 public static void SetCloseIEHandler(bool clickOk) { closeIeHandler = new CloseIEDialogHandler(clickOk); BaseIEController.IE.DialogWatcher.Add(closeIeHandler); } private static void ClearDialogHandler(IDialogHandler dialogHandler) { if (BaseIEController.IE.DialogWatcher.Contains(dialogHandler)) { BaseIEController.IE.DialogWatcher.Remove(dialogHandler); dialogHandler = null; } } 
-2
source

Source: https://habr.com/ru/post/1401683/


All Articles