微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

与自动化元素一起工作

如何解决与自动化元素一起工作

| 我想测试由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);
}
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。