开发者

How to work with AutomationElement in C# properly

开发者 https://www.devze.com 2023-03-13 06:45 出处:网络
I want to test a windows application that is formed with Windows Forms. I decided to work with the library AutomationElements.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号