一 准备
.NetFramework 4.8
FlaUI.UIA3 4.0.0
FlaUInspect V1.3.0
1下载FlaUInspect
https://github.com/FlaUI/FlaUInspect
FlaUInspect V1.3.0
百度网盘下载
2 NuGet 引用 flaUI.UIA3 4.0.0
二代码部分
1 引用FlaUI
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;
using FlaUI.Core.WindowsAPI;
using FlaUI.UIA3;
2 代码全部
class Program
{//1.GetWindowText 获取给定窗口句柄的窗口标题[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern bool SwitchToThisWindow(IntPtr hWnd, bool fAltTab);[STAThread]//启动单一现场static void Main(string[] args){Process[] processes = Process.GetProcessesByName("WeChat");if (processes.Count() != 1){Console.WriteLine("微信未启动或启动多个微信");}else{//1.附加到微信进程using (var app = Application.Attach(processes.First().Id)){using (var automation = new UIA3Automation()){//2.获取主界面var mainWindow = app.GetMainWindow(automation);//窗口置顶显示 避免其它窗口遮挡影响后续操作IntPtr handle = processes.First().MainWindowHandle;SwitchToThisWindow(handle, true); // 激活,显示在最var childWind = mainWindow.FindChildAt(1).FindChildAt(0).FindChildAt(1).FindChildAt(0).FindChildAt(0).FindChildAt(0);childWind.DrawHighlight(System.Drawing.Color.Red);childWind.Click();//搜索"文件传输助手"Keyboard.Type("文件传输助手");Thread.Sleep(800);//回车Keyboard.Type(VirtualKeyShort.RETURN);Thread.Sleep(800);//输入内容Keyboard.Type("文件传输助手");Thread.Sleep(800);//回车Keyboard.Type(VirtualKeyShort.RETURN);}}}}
}
三 原理如下
FlaUInspect V1.3.0
查找pane 节点 1,0,1,0,0,0
找到搜索
mainWindow.FindChildAt(1).FindChildAt(0).FindChildAt(1).FindChildAt(0).FindChildAt(0).FindChildAt(0);
根据FlaUInspect提示信息 可以做自动化辅助工具
演示代码下载