【问题标题】:UI automation with excel使用 Excel 实现 UI 自动化
【发布时间】:2017-11-29 01:50:22
【问题描述】:

我是 UI 自动化的新手。在我目前的组织中,我的任务是使用 GUI(图形用户界面)屏幕阅读制作一个自动化工具,但由于屏幕分辨率的差异,它不能与我同事的其他机器完美配合。

我观看了 YouTube 上的 this 链接,尝试了解使用 excel 进行 UI 自动化,但我在其他任何地方都找不到关于此主题的更多信息。

谁能指导我获取有关 UI 自动化的资源?我想知道在哪里可以学习它、阅读它以及如何使用 Excel 来实现它。

在此先感谢,如果有人可以帮助我,我真的很感激。

【问题讨论】:

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


【解决方案1】:

Microsoft 的 UIAutomation 功能非常强大,可与 Windows 7、8、10 以及 Visual Basic 的应用程序(32 位和 64 位)配合使用,并且无需昂贵的工具即可方便地用于执行一些不错的 GUI 自动化。

确保在 VBA 参考中你有 UIAutomationCore.Dll 参考(在某些计算机上很奇怪,有时你必须将它复制到你的文档文件夹中)

您可以在下面看到 2 个基本示例,但由于 MS 自动化是一个包含所有例程的庞大库,您可以在 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    

【讨论】:

  • 你能给我们提供“clsUIA”类吗?
  • 这将是一个名为 clsUIA 的类模块,其逻辑类似于 Dim c As New CUIAutomation function oDesktop return c.getrootelement end function
  • 非常感谢。您能否在单独的答案中提供整个代码?
【解决方案2】:

似乎您正在使用坐标进行自动化,当您切换到其他分辨率时,坐标会发生变化。如果是这种情况,请使用 ID、Class、Xpath、CSS 等自动化您的应用程序。此链接将帮助您:http://www.guru99.com/locators-in-selenium-ide.html

对于使用 Excel 的自动化,请查看以下链接: http://www.guru99.com/all-about-excel-in-selenium-poi-jxl.html

【讨论】:

  • OP 要求在 Excel 中实现这个过程,这对我来说意味着他们想要自动化不一定是 HTML 的应用程序。我的理解是 Selenium 是为与 HTML 应用程序交互而设计的。 Selenium 可以与非 HTML 的 Windows 对象交互吗?
【解决方案3】:

创建 clsUIA 类然后插入此代码 'clsUIA 有一些类似的逻辑

'start by add the following code
Dim  c As New CUIAutomation
Public oCUIAutomation As New CUIAutomation
Function oDesktop() As IUIAutomationElement
Set oDesktop = c.GetRootElement
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-10
    • 2021-09-28
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多