【问题标题】:TextBox throws Unsupported Pattern in Value PatternTextBox 在值模式中抛出不受支持的模式
【发布时间】:2017-01-20 18:13:25
【问题描述】:

有谁知道在运行时使用 UI 自动化和 .Net 启用 TextBox 后如何在 TextBox 中设置值?

更多信息:最初在加载应用程序时,TextBox 被禁用。使用自动化切换复选框后,文本框被启用。但是使用自动化是无法访问的。 我尝试了以下方法:

PropertyCondition parentProcCond = new PropertyCondition(AutomationElement.ProcessIdProperty, processes[0].Id);
Condition chkCondition = new AndCondition(
                            new PropertyCondition(AutomationElement.IsEnabledProperty, true),
                            new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox),
                            new PropertyCondition(AutomationElement.NameProperty, chkName));
//Find Elements
var parentElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, parentProcCond);

var chkUseMyAccountElement = parentElement.FindFirst(TreeScope.Descendants, chkCondition);
TogglePattern pattern = chkUseMyAccountElement.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
ToggleState state = pattern.Current.ToggleState;
if (state == ToggleState.On)
{
    pattern.Toggle();
}

Condition txtDomainCondition = new AndCondition(
                           new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text),
                           new PropertyCondition(AutomationElement.NameProperty, txtDomain)
                           );

var txtConditionElement = parentElement.FindFirst(TreeScope.Descendants, txtDomainCondition);
ValuePattern valuetxtDomain = txtConditionElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
valuetxtDomain.SetValue("US");

它在 ValuePattern Line 中抛出一个不受支持的模式。

【问题讨论】:

    标签: c# c#-4.0 automation ui-automation microsoft-ui-automation


    【解决方案1】:

    我找到了答案。

    而不是Control Type为Text,修改为Control Type为Edit。它正在工作。

     Condition txtDomainCondition = new AndCondition(
                           new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
                           new PropertyCondition(AutomationElement.NameProperty, txtDomain)
                           );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-30
      • 2022-09-27
      • 1970-01-01
      • 2021-06-12
      • 2019-01-07
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多