在 Katalon Studio 中,当 iOS 应用程序的元素没有标签或名称对象属性时如何点击它
In Katalon Studio how to tap an iOS app’s element when it doesn’t have either label or name object properties
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 的起始值和结束值或多或少是恒定的。
xpath 常量起始值为://XCUIElementTypeApplication/XCUIElementTypeWindow1
xpath 常量结尾值为:/XCUIElementTypeTabBar1/XCUIElementTypeButton[6]
我尝试过使用 xpath 开始值和结束值,但它没有用。因此,我们将不胜感激任何建议。它们如下:
xpath 以选定的定位器值结束:
/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[6][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’])]
xpath 以选定的定位器值开始:
//XCUIElementTypeApplication/XCUIElementTypeWindow[1][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’])]
DOM 树片段:
如果您可以修改源代码,将有一种简单的方法可以避免这种情况:
-向元素添加唯一的属性 (<... data-tagging="ThisIsMyUniqueTag">...
-在 Katalon 的对象定义中,添加一个名为 data-tagging 的属性并将值设置为您的唯一标签
-仅使用它来定位对象(如果出现多次,您可能想使用不同的标签,或者 select 特定的标签 [1])
优点:高效,增加可维护性,在更改其他内容时不会中断
缺点:您需要能够做到这一点
否则尝试检查并手动编写一个 selector。你能提供一些 DOM-tree 的样本吗?
经过一番挖掘和研究,我发现了以下解决问题的方法:
1) With the help of appium-desktop, I was able to get the (x,y)
co-ordinates of the element. Then in KS, I used the method called
tapAtPosition(x,y) to tap at the icon. However, this is not the final
way I ended up using.
2) I ended up creating a relative xpath for the element using KS spy
mobile. This was my final relative xpath for the element:
//*/XCUIElementTypeButton[6]
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 的起始值和结束值或多或少是恒定的。 xpath 常量起始值为://XCUIElementTypeApplication/XCUIElementTypeWindow1 xpath 常量结尾值为:/XCUIElementTypeTabBar1/XCUIElementTypeButton[6]
我尝试过使用 xpath 开始值和结束值,但它没有用。因此,我们将不胜感激任何建议。它们如下:
xpath 以选定的定位器值结束:
/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[6][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’])]
xpath 以选定的定位器值开始:
//XCUIElementTypeApplication/XCUIElementTypeWindow[1][count(. | //[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’]) = count(//[@type = ‘XCUIElementTypeButton’ and @enabled = ‘true’])]
DOM 树片段:
如果您可以修改源代码,将有一种简单的方法可以避免这种情况:
-向元素添加唯一的属性 (<... data-tagging="ThisIsMyUniqueTag">...
-在 Katalon 的对象定义中,添加一个名为 data-tagging 的属性并将值设置为您的唯一标签
-仅使用它来定位对象(如果出现多次,您可能想使用不同的标签,或者 select 特定的标签 [1])
优点:高效,增加可维护性,在更改其他内容时不会中断 缺点:您需要能够做到这一点
否则尝试检查并手动编写一个 selector。你能提供一些 DOM-tree 的样本吗?
经过一番挖掘和研究,我发现了以下解决问题的方法:
1) With the help of appium-desktop, I was able to get the (x,y) co-ordinates of the element. Then in KS, I used the method called tapAtPosition(x,y) to tap at the icon. However, this is not the final way I ended up using.
2) I ended up creating a relative xpath for the element using KS spy mobile. This was my final relative xpath for the element: //*/XCUIElementTypeButton[6]