In Katalon Studio how to tap an iOS app’s element when it doesn’t have either label or name object properties

折月煮酒 提交于 2019-12-11 06:06:45

问题


KS 6.3.2 is able to tap on an element that contains label or name object properties. However, the application that I have under test has an element which is a button and does not contain either label or name or any text. Furthermore, the xpath of that element is dynamic.

The following are the snapshots of the Object’s properties of the same element of an application captured from 2 different devices:

The following is the Selected Locator’s value:

My Page 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’])]

My Page 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’])]

As you can see above that the following object properties values are not static: width x y xpath

However, the xpath’s starts-with and ends-with values are more or less constant. xpath constant starts-with value is: //XCUIElementTypeApplication/XCUIElementTypeWindow1 xpath constant ends-with value is: /XCUIElementTypeTabBar1/XCUIElementTypeButton[6]

I have tried with xpath starts-with and ends-with values but it didn’t work. So any suggestion will be highly appreciated. They are as follows:

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’])]

DOM tree snippet:


回答1:


There would be an easy way to avoid this if you can modify the source:

-Add a unique property to the element (<... data-tagging="ThisIsMyUniqueTag">...

-In the objects definition in Katalon, add an attribute called data-tagging and set the value to your unique tag

-Use only that to locate the object (if there are multiple occurances you might wanna use different tags, or select a specific one [1])

Pros: Efficient, increases maintainability, doesn't break when other things are changed Con: You need to be able to do that

Otherwise try to inspect the and manually write a selector. Could you provide some sample of the DOM-tree?




回答2:


After some digging and research, I found the following methods to solve my problem:

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]



来源:https://stackoverflow.com/questions/57721320/in-katalon-studio-how-to-tap-an-ios-app-s-element-when-it-doesn-t-have-either-la

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!