2

Kann jemand einen Wert in der TextBox nach der Aktivierung von TextBox in Runtime mit UI Automation und .Net festlegen?TextBox löst nicht unterstütztes Muster im Wertmuster

Weitere Informationen: anfänglich beim Laden der Anwendung wurde die TextBox deaktiviert. Nachdem Sie das Kontrollkästchen mit Automation aktiviert haben, wurde die TextBox aktiviert. Aber mit Automatisierung ist es nicht zugänglich. Ich hat versucht, die folgende Art und Weise:

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"); 

Es wirft ein nicht unterstütztes Muster in Valuepattern-Linie.

Antwort

2

Ich fand die Antwort.

Anstelle von Steuerelementtyp als Text, geändert als Steuerelementtyp als Bearbeiten. Es funktioniert.

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