WatiN LogonDialogHandlers 在 Windows 7 中无法正常工作

编程入门 行业动态 更新时间:2024-10-07 12:21:18
本文介绍了WatiN LogonDialogHandlers 在 Windows 7 中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我最近更新到了 Windows 7、VS2010 和 IE8.我们有一个使用 WatiN 对 IE 运行测试的自动化套件.这些测试需要使用登录对话框处理程序,以便将不同的 AD 用户登录到 IE 浏览器.

I have recently updated to Windows 7, VS2010 and IE8. We have an automation suite running tests against IE using WatiN. These tests require the logon dialog handler to be used in order to log different AD Users into the IE Browser.

这在使用 Windows XP 和 IE8 时完美运行,但现在使用 Windows 7 导致不再识别 Windows 安全对话框,该对话框只是被忽略.这是用于启动浏览器的方法:

This works perfectly when using Windows XP and IE8, but now using Windows 7 has resulted in the Windows Security dialog box no longer being recognised, the dialogue box is just being ignored. This is the method being used to startup the browser:

        public static Browser StartBrowser(string url, string username, string password)
        {
            Browser browser = new IE();
            WatiN.Core.DialogHandlers.LogonDialogHandler ldh = new WatiN.Core.DialogHandlers.LogonDialogHandler(username, password);
            browser.DialogWatcher.Add(ldh);
            browser.GoTo(url);
            return browser;
        }

任何建议或帮助将不胜感激...

any suggestions or help would be greatly appreciated...

推荐答案

无论出于何种原因,Clint 发布的代码都有评论而不是输入用户名、密码和提交,并且引用了未定义的方法,但其他方面都可以.这是一些完成(和工作)的代码:

For whatever reason the code Clint posted had comments instead of entering the username, password and submitting, and referenced an undefined method, but is otherwise OK. Here's some completed (and working) code:

    public static Browser Win7Login(string username, string password, string URL) {
        Process ieProcess = Process.Start("iexplore.exe", URL);
        ieProcess.WaitForInputIdle();

        Thread.Sleep(2000);

        AutomationElement ieWindow = AutomationElement.FromHandle(ieProcess.MainWindowHandle);
        string t = ieWindow.Current.ClassName.ToString();

        Condition conditions = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
                                   new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
        Condition List_condition = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
                                        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
        Condition Edit_condition = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
                                    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
        Condition button_conditions = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true),
                                     new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));

        AutomationElementCollection c = ieWindow.FindAll(TreeScope.Children, conditions);
        foreach (AutomationElement child in c) {
            if (child.Current.ClassName.ToString() == "#32770") {
                // find the list
                AutomationElementCollection lists = child.FindAll(TreeScope.Children, List_condition);
                // find the buttons
                AutomationElementCollection buttons = child.FindAll(TreeScope.Children, button_conditions);

                foreach (AutomationElement list in lists) {
                    if (list.Current.ClassName.ToString() == "UserTile") {
                        AutomationElementCollection edits = list.FindAll(TreeScope.Children, Edit_condition);
                        foreach (AutomationElement edit in edits) {
                            if (edit.Current.Name.Contains("User name")) {
                                edit.SetFocus();
                                ValuePattern usernamePattern = edit.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                                usernamePattern.SetValue(username);
                            }
                            if (edit.Current.Name.Contains("Password")) {
                                edit.SetFocus();
                                ValuePattern passwordPattern = edit.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                                passwordPattern.SetValue(password);
                            }
                        }
                    }
                }
                foreach (AutomationElement button in buttons) {
                    if (button.Current.AutomationId == "SubmitButton") {
                        InvokePattern submitPattern = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                        submitPattern.Invoke();
                        break;
                    }
                }
            }
        }
        return IE.AttachTo<IE>(Find.By("hwnd", ieWindow.Current.NativeWindowHandle.ToString()), 30);
    }

这篇关于WatiN LogonDialogHandlers 在 Windows 7 中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 21:29:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142705.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   WatiN   LogonDialogHandlers   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!