有没有人知道如何在运行时使用UI Automation和.Net启用TextBox后在TextBox中设置值?
有关详细信息:最初在加载应用程序时,TextBox已禁用。使用Automation切换复选框后,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中抛出一个不支持的模式。
答案 0 :(得分:2)
我找到了答案。
而不是将Control Type作为Text,将Control Type修改为Edit。它正在发挥作用。
Condition txtDomainCondition = new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
new PropertyCondition(AutomationElement.NameProperty, txtDomain)
);