Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 登录对话框处理程序windows 7_C#_Watin - Fatal编程技术网

C# 登录对话框处理程序windows 7

C# 登录对话框处理程序windows 7,c#,watin,C#,Watin,} At行:公共覆盖布尔句柄对话框(窗口) 它需要一个窗口的值,因为我正在测试一个网站,我没有该窗口的名称或代码。 请为这项工作推荐一个替代方案您到底想要什么?它是一个窗口(对话框),其中有两个文本字段和一个提交凭据的按钮?该对话框是否从您的web应用程序启动?检查[out…可能会帮到你…谢谢,Sham_No.我没有这个窗口的源代码,它不是那样工作的..在windows 7中是否有其他方法来处理登录对话框处理程序是的。当我打开网站时,它首先给出一个登录提示,其中有两个文本字段来输入用户名和密码,

}

At行:公共覆盖布尔句柄对话框(窗口) 它需要一个窗口的值,因为我正在测试一个网站,我没有该窗口的名称或代码。
请为这项工作推荐一个替代方案

您到底想要什么?它是一个窗口(对话框),其中有两个文本字段和一个提交凭据的按钮?该对话框是否从您的web应用程序启动?

检查[out…可能会帮到你…谢谢,Sham_No.我没有这个窗口的源代码,它不是那样工作的..在windows 7中是否有其他方法来处理登录对话框处理程序是的。当我打开网站时,它首先给出一个登录提示,其中有两个文本字段来输入用户名和密码,还有两个按钮“确定”和“取消”,并且没有源代码code用于登录提示,因此我必须在我的c#code中使用watin来处理该提示。对于使用watin的windows,没有完整的解决方案。您需要使用不同的工具来处理它。或者作为临时解决方案。尝试发送键(假设焦点在对话框中)`System.windows.Forms.SendKeys.SendWait(用户名);System.windows.Forms.SendKeys.SendWait({TAB}”);System.Windows.Forms.SendKeys.SendWait(密码);System.Windows.Forms.SendKeys.SendWait(“{TAB}”);System.Windows.Forms.SendKeys.SendWait(“{ENTER}”);我使用的是一个有登录对话框的web应用程序。你能推荐任何与平台无关的替代测试工具吗?比如Watin,我可以处理登录拨号,即使你使用的是web应用程序,上面的代码也应该适合你…有许多Windows(GUI)工具自动化。如CodedUI、AutoIt……等。由于您熟悉C#,我建议您使用编码UI[。生成代码后,您甚至可以将其添加到现有脚本中。或者AutoIt,这是一种基于脚本的框架,使用VB脚本。
using System.Windows.Automation;
using System.Linq;
using WatiN.Core.DialogHandlers;
using WatiN.Core.Native.Windows;

namespace DialogHandlers
{
public class Windows7LogonDialogHandler : LogonDialogHandler
{
    #region Private Fields

    private readonly string _mUsername;
    private readonly string _mPassword;
    private readonly AndCondition _mListCondition = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
    private readonly AndCondition _mEditCondition = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
    private readonly AndCondition _mButtonConditions = new AndCondition(new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));

    #endregion

    #region Constructor

    public Windows7LogonDialogHandler(string username, string password)
        : base(username, password)
    {
        _mUsername = username;
        _mPassword = password;
    }

    #endregion

    #region Public Members

    public override bool HandleDialog(Window window)
    {
        if (CanHandleDialog(window))
        {
            var win = AutomationElement.FromHandle(window.Hwnd);
            var lists = win.FindAll(TreeScope.Children, _mListCondition);
            var buttons = win.FindAll(TreeScope.Children, _mButtonConditions);
            var another = (from AutomationElement list in lists
                           where list.Current.ClassName == "UserTile"
                           where list.Current.Name == "Use another account"
                           select list).First();
            another.SetFocus();

            foreach (var edit in from AutomationElement list in lists
                                 where list.Current.ClassName == "UserTile"
                                 select list.FindAll(TreeScope.Children, _mEditCondition)
                                     into edits
                                     from AutomationElement edit in edits
                                     select edit)
            {
                if (edit.Current.Name.Contains("User name"))
                {
                    edit.SetFocus();
                    var usernamePattern = edit.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                    if (usernamePattern != null) usernamePattern.SetValue(_mUsername);
                }
                if (edit.Current.Name.Contains("Password"))
                {
                    edit.SetFocus();
                    var passwordPattern = edit.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                    if (passwordPattern != null) passwordPattern.SetValue(_mPassword);
                }
            }
            foreach (var submitPattern in from AutomationElement button in buttons
                                          where button.Current.AutomationId == "SubmitButton"
                                          select button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern)
            {
                submitPattern.Invoke();
                break;
            }
            return true;
        }
        return false;
    }

    public override bool CanHandleDialog(Window window)
    {
        return window.ClassName == "#32770";
    }

    #endregion
}