【问题标题】:Winium - how to access tool bar item if that bar doesn't have childWinium - 如果该栏没有子项,如何访问工具栏项目
【发布时间】:2018-06-06 14:55:28
【问题描述】:

我正在使用 Winium + Java 对 Windows 应用程序进行自动化测试,并尝试访问工具栏菜单。
当我尝试使用 UI 自动化验证检测元素时,我看不到工具栏元素下的子元素,如下图所示。 enter image description here

但是我的工具栏肯定有像截图这样的子菜单项,我需要访问它们。 enter image description here

我尝试了下面的java代码,但没有成功

WebElement el = driver.findElement(By.id('59398'));
el.click();
WebElement child = el.findElement(By.name('Start'));
child.click();

当我尝试时

driver.findElement(By.name"Start').click();

它点击了我的 Windows 开始菜单,而不是我的应用程序菜单。

有什么方法可以访问这个工具栏下的项目吗?

【问题讨论】:

    标签: java automation


    【解决方案1】:

    您可以尝试使用其他 UI Inspector 例如。 UI SPY 或 Inspector.exe

    可能您的 ID 不是 AutomationID(进程 ID?)

    您应该找到一个主窗口(您的应用程序的父级)(计算示例)并获取一个参数,如 AutomationId、ClassName 或 Name

    【讨论】:

      【解决方案2】:

      我看到这是 MFC 应用程序,这是一个应用程序端 MFC 库问题。如果您使用 Inspect.exe 将鼠标悬停在工具栏按钮上,则信息可用,但您无法从层次结构中访问此按钮(按钮不知何故没有父级)。可能的解决方法涉及结合 Win32 API 和 UI 自动化方法:

      1. 使用 Win32 API 获取按钮矩形(但没有文本)。
      2. 使用 UI Automation API 的ElementFromPoint 方法,获取实际文本以选择正确的按钮。

      附:我的建议理论上适用于 Java + Winium。但我无法估计复杂性,因为我不是 Java 专家。所以下面是 Python 解决方案。

      我们计划在 pywinauto 中实现这种混合方式。见issue #413。它包含如何做到这一点的 Python 代码示例。我们还没有机会整合它。

      from ctypes.wintypes import tagPOINT
      import pywinauto
      
      app = pywinauto.Application().start(r'.\apps\MFC_samples\RebarTest.exe')
      
      menu_bar = app.RebarTest.MenuBar.wrapper_object()
      point = menu_bar.button(0).rectangle().mid_point()
      point = menu_bar.client_to_screen(point)
      
      elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(point[0], point[1]))
      element = pywinauto.uia_element_info.UIAElementInfo(elem)
      print(element.name)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-11
        • 1970-01-01
        • 2021-05-10
        相关资源
        最近更新 更多