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

本文关键字:自动化 机器 程机器 可以使 UI 我们 | 更新日期: 2023-09-27 18:35:56

我有登录到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,但无法检查远程机器窗口中的元素。 请提供想法。

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

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