Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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# 使用UIAutomation选择网格中存在的复选框_C#_Ui Automation_Microsoft Ui Automation - Fatal编程技术网

C# 使用UIAutomation选择网格中存在的复选框

C# 使用UIAutomation选择网格中存在的复选框,c#,ui-automation,microsoft-ui-automation,C#,Ui Automation,Microsoft Ui Automation,使用UIAutomation选择网格中存在的复选框。下面的代码返回invalidpattern作为调用模式: AutomationElement mainGrid = appElement1.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "ReadinessTestList")); // find the grid in the window if (

使用UIAutomation选择网格中存在的复选框。下面的代码返回invalidpattern作为调用模式:

AutomationElement mainGrid = appElement1.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "ReadinessTestList"));
// find the grid in the window 
if (mainGrid != null)
 {

    MessageBox.Show("inside the grid");

    // select just the first cell 
    var item = mainGridPattern.GetItem(0, 0);
    MessageBox.Show(Convert.ToString(item));
    //item.SetFocus();

    AutomationElement FirstCheckBox = GetTextElement(item, "SystemNameCheckBox");

    if (FirstCheckBox != null)
    {
        MessageBox.Show(Convert.ToString(FirstCheckBox));
        TogglePattern SelectedFirstCheckBox = FirstCheckBox.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
        MessageBox.Show(Convert.ToString(SelectedFirstCheckBox));

        ToggleState FirstCheckBxState = SelectedFirstCheckBox.Current.ToggleState;
        string try2 = Convert.ToString(FirstCheckBxState);
        MessageBox.Show(try2);

        //FirstCheckBxState.On;

        if (FirstCheckBxState != ToggleState.On) // not on? click it
        {            
            InvokePattern invokefirstCheckBox = (InvokePattern)FirstCheckBox.GetCurrentPattern(InvokePattern.Pattern);
            Thread.Sleep(2000);
            invokefirstCheckBox.Invoke();
        }

    }
对于复选框,应该使用调用模式,而不是调用模式

 TogglePattern tpToggle = (TogglePattern)aeElement.GetCurrentPattern(TogglePattern.Pattern);
 tpToggle.Toggle();
此外,安装后还应使用inspect.exe,该文件位于C:\Program Files(x86)\Windows Kits\8.1\bin\x86。此工具将允许您查看您尝试自动化的支持模式