RPA对微信和企业微信的UI元素探测

元素定位原理(用.net自己写一个试一试)

windows10 下UI自动化框架存在于下列路径:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2

2018/03/26  16:24            46,776 UIAutomationClient.dll
2018/03/26  16:24            28,904 UIAutomationClientsideProviders.dll
2018/03/26  16:24            31,424 UIAutomationProvider.dll
2018/03/26  16:24            39,600 UIAutomationTypes.dll

早期我们去探测windows元素用SPY++或者User32.Dll调用可以很方便的获取到句柄

原理如下:鼠标坐标或者标题、类名

        [DllImport("user32.dll", EntryPoint = "WindowFromPoint")]//指定坐标处窗体句柄
        public static extern int WindowFromPoint(
            int xPoint,
            int yPoint
        );
IntPtr hwnd = WindowFromPoint(point.X, point.Y);//获取指定坐标处窗口的句柄
IntPtr hwnd = Win32.FindWindow(lpszClass, lpWindowName);

由于windows从System.Windows.Forms到Windows.UI.Core 很多自定义的控件出现了,我们无法通过句柄探测到元素。微软的自动化dll对部分UI元素不能获取。

下面是使用了微软UIAutomation 中的 AutomationElement能力对企业微信进行了探测:

AutomationElement element = AutomationElement.FromPoint(new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y));

通过测试无论鼠标定位在哪里,我们探测的始终为顶层菜单。

接下来我使用(影刀、Power Automate、uiBot、实在智能)RPA工具进行了微信及企业微信测试,如下结果:

acc:Windows.UI.Core.CoreWindow
whd:windowsHandle
uia:AutomationElement
cv

 影刀

 

 

 

微软Power Automate

 

uiBot

 

 

 

实在智能

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐