无法使用Winium for Python为桌面应用程序测试选择列表/表对象上的行

2024-04-20 09:12:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Winium和Python来自动化一个桌面应用程序,但我遇到了GUI的一部分自动化问题。在

在创建配置的过程中,用户将有一个窗口,在其中选择要创建的协议类型。在

enter image description here

我遇到的问题是通过鼠标单击在表中选择一个特定的行。由于有多行具有相同的协议名,我想根据协议名和模式(即Modbus Slave)选择一行。在

理想情况下,我希望搜索表,根据protocol&mode找到所需的行,然后选择该行。我已经知道如何只使用协议名来选择行:

driver.find_element_by_class_name("WindowsForms10.SysListView32.app.0.141b42a_r9_ad1").find_element_by_id("LargeIncrement").click()
driver.find_element_by_class_name("WindowsForms10.SysListView32.app.0.141b42a_r9_ad1").find_element_by_name("Modbus").click()

我遇到的问题是找到一种基于这两个参数选择行的方法。在webui测试中,它通常是一个'/td'或'/tr'对象,我可以很容易地在HTML代码中找到列表/表,并使用其XPath指定行或行中的单元格。我的桌面应用不是这样。我一直试图同时使用Inspect Object(7.2.0.0版)。。。在

enter image description here

。。。和UISpy(3.0.0.0版)。。。在

enter image description hereenter image description here

。。。但还没能想出如何执行这个动作。通过一些研究和搜索,我尝试了以下几种组合:

^{pr2}$

我做了一些元素挖掘,发现有182个Xpath对象。在

protocol_table = driver.find_element_by_class_name("WindowsForms10.SysListView32.app.0.141b42a_r9_ad1")

all_xpath_children = protocol_table.find_elements_by_xpath(".//*")
print "Length:" + str(len(all_xpath_children))

我肯定有办法做到这一点,但我正在努力想办法。我发现的文档很少,而且我发现的大多数帮助都是针对Java的。在

更新(1)2019年4月24日 我还单独查看了列表中的项目,希望找到执行此操作的方法。以下是列表/表格中其中一项的信息:

检查对象-Modbus从机enter image description hereenter image description hereenter image description hereenter image description here

UISpy-Modbus从站 enter image description hereenter image description hereenter image description hereenter image description here

更新(2)2019年4月24日 我发现了一些有用的东西。当我在上面的屏幕上显示一个相同的文本时,我注意到在上面的一个文本中显示了一个相同的文本。因此,我开始使用该参数测试不同的可能性,以及上面使用XPath的成功经验。我发现下面3个选项都可以选择表中的Modbus从线路:

driver.find_element_by_class_name("WindowsForms10.SysListView32.app.0.141b42a_r9_ad1").find_element_by_xpath("(//*[@LocalizedControlType='text'])[79]").click()
driver.find_element_by_class_name("WindowsForms10.SysListView32.app.0.141b42a_r9_ad1").find_element_by_xpath("(//*[@LocalizedControlType='text'])[80]").click()
driver.find_element_by_class_name("WindowsForms10.SysListView32.app.0.141b42a_r9_ad1").find_element_by_xpath("(//*[@LocalizedControlType='text'])[81]").click()

选择对象78将导致选择Modbus主机,选择对象82将导致选择下一行。此方法可以工作,但最好能找到一种更简洁的方法来选择既知道“协议”又知道“模式”的行。在


Tags: 方法name协议bydriverelementfindxpath