excel - 使用 excel 实现 UI 自动化

标签 excel user-interface ui-automation ios-ui-automation vba

我是 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/

选项显式

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/

相关文章:

Excel : Select max and min Datetime in a row

excel - 如何在Excel中自动删除行

JavaFX - 无法在 ChoiceBox 上调用 setOnAction()?

ios - IOS 中的 UIAutomation 错误

reactjs - Testcafe - 单击按钮后如何获取更新状态值

php - 将 mysql 查询从 php 网页保存到 excel 文件

excel - 从 VBScript 使用 Excel 的 UpdateLink() 方法

c# - 如何获取在特定点接收鼠标点击的 Control/Windows Handle/AutomationElement?

ios - 快速发送ui数据

web-services - 如何在 RESTful Web 应用程序中映射不同的 UI View ?