2

Does anyone know how to set a value in the TextBox after enabling TextBox in runtime using UI Automation and .Net?

For more information: initially while loading the application, the TextBox was disabled. After toggling the check box using Automation, the TextBox got enabled. But using automation it is not accessible. I tried the following way:

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

It throws an Unsupported Pattern in ValuePattern Line.

Britto Raj
  • 401
  • 1
  • 5
  • 15

1 Answers1

2

I found the answer.

Instead of Control Type as Text, modified as Control Type as Edit. It is working.

 Condition txtDomainCondition = new AndCondition(
                       new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
                       new PropertyCondition(AutomationElement.NameProperty, txtDomain)
                       );
Britto Raj
  • 401
  • 1
  • 5
  • 15