作为练习,我尝试使用FlaUI自动输入RDP凭据。我的操作系统是Windows 10。
我能够启动mstsc.exe并在此窗口中键入:
但是我拿到这扇窗户,却找不到它:
它不是mstsc窗口,尽管它上方显示为一个模态窗口: mstsc总是只有一个窗口。显然这是“凭证管理器UI主机”的窗口,但是这个过程.没有窗户。
即使在任务管理器中,它也是在后台任务中列出的,而不是在应用程序部分。FlaUI检查根本没有看到它。
顺便说一句,这是我的代码:
var CurrentAutomation = new UIA3Automation();
var Process = Application.Attach(Process.GetProcessesByName("CredentialUIBroker")[0]);
var Windows = Process.GetAllTopLevelWindows(CurrentAutomation); // 0 elements
如何获得此窗口的句柄并使用FlaUI访问其文本框?
发布于 2020-04-02 16:36:22
事实证明,这只是知道“窗口”的名称的问题,该窗口是凭据Dialog主机;而且,可以使用FlaUI检查找到它。
一旦完成了mstsc部分,并出现了"Windows Security“窗口,您可以继续使用以下示例代码:
// Declare all variables, which might be method parameters instead
var Password = "MyLamePassword";
var MaxTimeout = new TimeSpan(10 * 1000 * 2000);
var CurrentAutomation = new UIA3Automation();
var Desktop = CurrentAutomation.GetDesktop();
// Get the window, using a Retry call to wait for it to be available
var CredentialWindow = Retry
.WhileEmpty(
() => Desktop.FindAllDescendants(f => f.ByClassName("Credential Dialog Xaml Host")),
timeout: MaxTimeout,
throwOnTimeout: true)
.Result[0];
// Get the password box
AutomationElement PasswordBox = null;
Retry.WhileNull(
() => PasswordBox = CredentialWindow.FindFirstDescendant(f => f.ByName("Password").And(f.ByControlType(ControlType.Edit))),
timeout: MaxTimeout,
throwOnTimeout: true);
// Type the password
PasswordBox.FocusNative();
Keyboard.Type(Password);
// I have some Retry code here too, just to check that the password is actually typed, and type Enter after it.
CurrentAutomation.Dispose();
https://stackoverflow.com/questions/60988380
复制相似问题