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!
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);
}
精彩评论