我们可以使用UI自动化自动化远程机器

时间:2016-02-24 09:52:17

标签: c# automation microsoft-ui-automation

我有登录rdp的代码,但我无法检查任何元素:

using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Automation;
using System.Windows.Forms;
using OpenQA.Selenium.Interactions;


namespace AutoTest
{
    class RAAdmin
    {
        public void RuleTestExistingUserName()
        {
            var RDP = Process.Start("mstsc.exe");
            Thread.Sleep(3000);
            var _remoteRDP = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Remote Desktop Connection"));
            AutomationElement rdpCombobox = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ComboBox"));
            AutomationElement rdpTextBox = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "Edit"));
            TextPattern targetTextPattern =              rdpTextBox.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
            targetTextPattern.DocumentRange.Select();
            Thread.Sleep(3000);
            SendKeys.SendWait("xxx.xxx.xx.xx");
            rdpCombobox = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ComboBox"));
            _remoteRDP = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Remote Desktop Connection"));
            SendKeys.SendWait("{ENTER}");
//clicks on connect button of rdp window.  

我能够登录到rdp,但无法检查远程机器窗口中的元素。请提供想法。

1 个答案:

答案 0 :(得分:1)

RDP不会将UI自动化请求转发到远程计算机,因此您将无法在远程计算机窗口中发现或检查元素。