Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

c# - Watin & IE9 - Cant click ok buttons

I'm using Watin to navigate through a large number of different websites, and I'm using the great solution here to automatically click ok on all the javascript and ie boxes that popup.

The problem is, this solution works great for ie6-ie8, but no longer works for IE9.

Does anyone have anyone suggestions on how to get IE9 to auto click/close all prompts?

(I'm using the latest Watin release, and the code below)

public class something {

public something() {
IE browser = new IE("about:blank");
addHandlers(browser);
.. do stuff with browser

}

  //Just click ok to everything
        private void addHandlers(Browser browser)
        {
                    browser.AddDialogHandler(new WatiN.Core.DialogHandlers.AlertAndConfirmDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.AlertDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.CertificateWarningHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.CloseIEDialogHandler(false));
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.ConfirmDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.DialogHandlerHelper());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.FileDownloadHandler("me.htm"));
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.FileUploadDialogHandler("me.htm"));             
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.PrintDialogHandler(WatiN.Core.DialogHandlers.PrintDialogHandler.ButtonsEnum.Cancel));
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.PromptDialogHandler(false));
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.RefreshWarningDialogHandler(false));
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.ReturnDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.SecurityAlertDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.SimpleJavaDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.SecurityAlertDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.AlertDialogHandler());
                browser.AddDialogHandler(new WatiN.Core.DialogHandlers.SimpleJavaDialogHandler());
                browser.AddDialogHandler(new OKDialogHandler());
            }

}


    public class OKDialogHandler : WatiN.Core.DialogHandlers.BaseDialogHandler
    {
        public override bool HandleDialog(Window window)
        {
            var button = GetOKButton(window);
            button.Click();   
            return false;
        }

        public override bool CanHandleDialog(Window window)
        {
            return GetOKButton(window) != null;
        }

        private WinButton GetOKButton(Window window)
        {
            var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button" && new WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
            if (windowButton == null)
                return null;
            else
                return new WinButton(windowButton.Hwnd);
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

WatiN 2.1 has recently been released which addresses a number of IE9 issues. You can download it from http://watin.org/ or update using NuGet:

PM> update-package watin


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...