Java Winium-如果工具栏项不存在,如何访问该项';我没有孩子
我正在使用Winium+Java对Windows应用程序进行自动化测试,并尝试访问工具栏菜单。Java Winium-如果工具栏项不存在,如何访问该项';我没有孩子,java,automation,Java,Automation,我正在使用Winium+Java对Windows应用程序进行自动化测试,并尝试访问工具栏菜单。 当我尝试使用UI Automation Verify检测元素时,我无法在工具栏元素下看到子元素,如下面的屏幕截图所示。 但我的工具栏肯定有子菜单项,如屏幕截图,我需要访问它们。 我尝试了下面的java代码,但没有成功 WebElement el = driver.findElement(By.id('59398')); el.click(); WebElement child = el.findE
当我尝试使用UI Automation Verify检测元素时,我无法在工具栏元素下看到子元素,如下面的屏幕截图所示。 但我的工具栏肯定有子菜单项,如屏幕截图,我需要访问它们。 我尝试了下面的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开始菜单,而不是我的应用程序菜单
有没有办法访问此工具栏下的项目?您可以尝试使用其他UI检查器 例如,UI SPY或Inspector.exe 您的ID可能不是AutomationID(进程ID?) 您应该找到一个主窗口(应用程序的父窗口)(例如calc)并获取一个参数,如AutomationId、ClassName或Name
您可以尝试使用另一个UI检查器 例如,UI SPY或Inspector.exe 您的ID可能不是AutomationID(进程ID?) 您应该找到一个主窗口(应用程序的父窗口)(例如calc)并获取一个参数,如AutomationId、ClassName或Name
我看到这是MFC应用程序,这是应用程序端的MFC库问题。如果使用Inspect.exe将鼠标悬停在工具栏按钮上,则信息可用,但无法从层次结构中访问此按钮(这些按钮不知何故没有父按钮)。可能的解决方法包括结合Win32 API和UI自动化方法:
ElementFromPoint
方法,并获取实际文本以选择正确的按钮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)
我看到这是MFC应用程序,这是一个应用程序端的MFC库问题。如果使用Inspect.exe将鼠标悬停在工具栏按钮上,则信息可用,但无法从层次结构中访问此按钮(这些按钮不知何故没有父按钮)。可能的解决方法包括结合Win32 API和UI自动化方法:
ElementFromPoint
方法,并获取实际文本以选择正确的按钮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)