Watin & IE9 - Cant click ok buttons

假如想象 提交于 2019-12-18 09:01:05

问题


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);
        }
    }

回答1:


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




回答2:


I was facing the same issue and no matter what I do it was not working until I found a workaround which take time but work for me.

The default time to elapse for WaitUntilExists() is 30 secs so when using it in IE9 provide extended time limit as following.

handler.WaitUntilExists(40); // or whatever time suits you above 30

It certainly take time but it works.



来源:https://stackoverflow.com/questions/5626538/watin-ie9-cant-click-ok-buttons

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