我是 UI 自动化的新手。在我目前的组织中,我的任务是使用 GUI(图形用户界面)屏幕阅读制作一个自动化工具,但由于屏幕分辨率不同,它无法与我同事的其他机器完美配合。
我看了this you-tube 上的链接以尝试使用 excel 了解 UI 自动化,但我在其他任何地方都找不到关于此主题的信息。
任何人都可以指导我获取有关 UI 自动化的资源吗?我想知道在哪里可以学习它、阅读它以及如何使用 Excel 实现它。
提前致谢 如果有人能帮助我,我将不胜感激。
最佳答案
Microsoft 的 UIAutomation 非常强大,适用于 Windows 7、8、10 以及适用于应用程序(32 位和 64 位)的 Visual Basic,并且可以方便地用于执行一些不错的 GUI 自动化,而无需昂贵的工具。
确保在 VBA 引用中你有 UIAutomationCore.Dll 引用(有时在某些计算机上很奇怪你必须将它复制到你的文档文件夹)
您可以在下面看到 2 个基本示例,但由于 MS Automation 是一个包含所有例程的庞大库,您可以在 MSDN 上阅读大量内容以获取完整文档。 我在 AutoIt 和 VBA 中使用 MS UIA 例程
- 对于 AutoIt,它在此处共享
https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/
- 对于 VBA,我没有标准库,但有人尝试过 这 https://github.com/mhumpher/UIAutomation_VBA
选项显式
Sub test()
Dim c As New CUIAutomation
Dim oDesktop As IUIAutomationElement
Set oDesktop = c.GetRootElement
Debug.Print oDesktop.CurrentClassName & vbTab & oDesktop.CurrentName & vbTab & oDesktop.CurrentControlType
End Sub
'Test uia just dumps all windows of the desktop to the debug window
Sub testUIA()
Dim allEl As IUIAutomationElementArray 'Returns an element array with all found results
Dim oElement As IUIAutomationElement 'Reference to an element
Dim ocondition As IUIAutomationCondition
Dim i As Long
Dim x As New clsUIA
'Just reference the three mainly used properties. many more are available when needed
Debug.Print x.oDesktop.CurrentName & x.oDesktop.CurrentClassName & x.oDesktop.CurrentControlType
Set ocondition = x.oCUIAutomation.CreateTrueCondition 'Filter on true which means get them all
Set allEl = x.oDesktop.FindAll(TreeScope_Children, ocondition) 'Find them in the direct children, unfortunately hierarchies are strange sometimes
'Just reference the three mainly used properties. many more are available when needed
For i = 0 To allEl.Length - 1
Set oElement = allEl.GetElement(i)
' If oElement.CurrentClassName = "PuTTY" Then
Debug.Print oElement.CurrentClassName & oElement.CurrentName & oElement.CurrentControlType
' Debug.Print oElement.CurrentBoundingRectangle
oElement.SetFocus
DoEvents
Sleep 2000
' End If
Next
End Sub
关于excel - 使用 excel 实现 UI 自动化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44756042/