1

I want to test a windows application that is formed with Windows Forms. I decided to work with the library AutomationElements.

The problem is that I don't know how to use it properly.

For example: How can I write in a textbox that I'm handling with AutomationElement?

The code is like:

var processStartInfo = new ProcessStartInfo(SATELITE_PATH);
var pSatelite = Process.Start(processStartInfo);
pSatelite.WaitForInputIdle();
Delay(2);
satelite = AutomationElement.RootElement.FindChildByProcessId(pSatelite.Id);
AutomationElement loginUser = satelite.FindDescendentByIdPath(new[] {"frmLogin", "txtUserName"});

I want to write the User in the loginUser. How can I do it?

Really thanks!

Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
Javi
  • 81
  • 12

1 Answers1

3

Use ValuePattern:

var processStartInfo = new ProcessStartInfo(SATELITE_PATH);
var pSatelite = Process.Start(processStartInfo);
pSatelite.WaitForInputIdle();
Delay(2);
satelite = AutomationElement.RootElement.FindChildByProcessId(pSatelite.Id);
AutomationElement loginUser = satelite.FindDescendentByIdPath(new[] {"frmLogin", "txtUserName"});

if (loginUser != null)
{
     ValuePattern valPattern = loginUser.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
     valPattern.SetValue(username);
}
theartwebreathe
  • 361
  • 3
  • 6