有谁知道如何在运行时使用 UI Automation 和 .Net 启用 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 行中抛出不支持的模式。
最佳答案
我找到了答案。
将控件类型修改为编辑控件类型,而不是文本控件类型。它正在工作。
Condition txtDomainCondition = new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
new PropertyCondition(AutomationElement.NameProperty, txtDomain)
);
关于c# - TextBox 在值模式中抛出不支持的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465019/