WatiN ie9 confirm dialog is not working [duplicate]

扶醉桌前 提交于 2019-12-13 07:39:26

问题


Possible Duplicate:
Watin & IE9 - Cant click ok buttons

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's not working on ie 9, javascript confirm I already use latest version 2.1


回答1:


ConfirmDialogHandler confirmHandler = new ConfirmDialogHandler();
        using (new UseDialogOnce(browser.DialogWatcher, confirmHandler))
        {
            confirmHandler.WaitUntilExists();

            confirmHandler.CancelButton.Click();
        }

it works on ie7, but not on ie 9 DrunkenMonkey's answer is not working

WatiN-2.1.0.1196




回答2:


If Your confirm dialog doesn't work in IE9, try next decision

(Visual studio 2010, Windows7, NetFramework 4.0, Internet explorer 9)

First you must add refernce UIAutomationClient and UIAutomationTypes to your test project.

The next method extends 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;

            }
        }



回答3:


I have the following code in my project:

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. Note that it is WatiN v2.0.50727, but I don't see that this should make a difference with you running v2.1.




回答4:


Watin has methods to handle dialogs. Try using this 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;
    }
}


来源:https://stackoverflow.com/questions/6544962/watin-ie9-confirm-dialog-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!