与自动化元素一起工作

| 我想测试由Windows窗体形成的Windows应用程序。我决定使用库自动化元素。 问题是我不知道如何使用它。例如:如何用自动化元素处理文本框中的内容? 代码如下:
        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\"});
我想在loginUser中写入User。我该怎么做? 真的感谢!     
已邀请:
        使用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);
}
    

要回复问题请先登录注册