【发布时间】: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