瓦廷& IE9 - 无法单击“确定”按钮

发布于 2024-10-31 18:59:39 字数 3243 浏览 2 评论 0原文

我正在使用 Watin 浏览大量不同的网站,并且我正在使用出色的解决方案 此处 自动在弹出的所有 javascript 和 ie 框中单击“确定”。

问题是,这个解决方案适用于 ie6-ie8,但不再适用于 IE9。

有人对如何让 IE9 自动单击/关闭所有提示有任何建议吗?

(我正在使用最新的 Watin 版本,以及下面的代码)

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟─花易冷 2024-11-07 18:59:39

WatiN 2.1 最近发布,解决了许多 IE9 问题。您可以从 http://watin.org/ 下载它或使用 NuGet 进行更新:

PM>更新包 watin

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

野稚 2024-11-07 18:59:39

我面临着同样的问题,无论我做什么,它都不起作用,直到我找到一个需要时间但对我有用的解决方法。

WaitUntilExists() 的默认运行时间为 30 秒,因此在 IE9 中使用它时,请提供如下延长的时间限制。

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

这当然需要时间,但确实有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文