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

最佳答案

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

关于c# - 我们可以使用UI自动化来自动化远程机器吗,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35598667/

10-11 02:02