KS 6.3.2 能够点击包含标签或名称对象属性的元素。但是,我正在测试的应用程序有一个按钮元素,不包含标签或名称或任何文本。此外,该元素的 xpath 是动态的。
以下是从 2 个不同设备捕获的应用程序的同一元素的对象属性的快照:
以下是 Selected Locator 的值:
我的第 1 页:
//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[6][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’ and @height = ‘96.0’ and @visible = ‘true’ and @width = ‘160.0’ and @x = ‘664.0’ and @y = ‘1628.0’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’ and @height = ‘96.0’ and @visible = ‘true’ and @width = ‘160.0’ and @x = ‘664.0’ and @y = ‘1628.0’])]
我的页面 2:
//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[6][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’ and @height = ‘96.0’ and @visible = ‘true’ and @width = ‘142.0’ and @x = ‘604.0’ and @y = ‘1238.0’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’ and @height = ‘96.0’ and @visible = ‘true’ and @width = ‘142.0’ and @x = ‘604.0’ and @y = ‘1238.0’])]
正如您在上面看到的,以下对象属性值不是静态的: 宽度 X 是 路径
但是,xpath 的起始值和结束值或多或少是恒定的。 xpath 常量起始值是://XCUIElementTypeApplication/XCUIElementTypeWindow 1 xpath 常量结尾值为:/XCUIElementTypeTabBar 1/XCUIElementTypeButton[6]
我已经尝试使用 xpath 开始值和结束值,但它没有用。因此,我们将不胜感激任何建议。它们如下:
xpath ends-with selected locators value:
/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[6][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’])]
xpath starts-with selected locators value:
//XCUIElementTypeApplication/XCUIElementTypeWindow[1][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’])]
最佳答案
如果您可以修改源代码,将会有一种简单的方法来避免这种情况:
-给元素添加一个独特的属性(<... data-tagging="ThisIsMyUniqueTag">...
-在Katalon的对象定义中,添加一个名为data-tagging的属性,并将值设置为你的唯一标签
-仅使用它来定位对象(如果出现多次,您可能想使用不同的标签,或选择一个特定的标签 [1])
优点:高效,增加可维护性,在更改其他内容时不会中断 缺点:你需要能够做到这一点
否则尝试检查并手动编写一个选择器。您能否提供一些 DOM 树示例?
关于ios - 在 Katalon Studio 中,当它没有标签或名称对象属性时如何点击 iOS 应用程序的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57721320/