Is it possible to convert Xpath to ID fast

In my project, I only have one selector locator using XPath.
I found it’s the same XPath if the indifferent page, so I don’t want to write more duplicated code about elements locator.

Provide screenshot of your inspector view. Will help you in getting different ways ( Using xpath , id, classname…etc) to find the element.

Pls see the pic, hope it’s useful to solve the issues.

@pothurajtharun

you can try selecting by class name

For specific statement I need to see the exact element your are searching for (just select it in “App Source”)

But you cannot select, right, at least now I cannot select, class name is not a good choice for iOS and android. @FurbnMax

@MarcSteven I have never done this with IOS, but for Android class name is better than XPath and if ID is not possible it is better and faster to use a combination of searchByClassName and searchByXpath since it is faster and more stable.

See https://appiumpro.com/editions/60-how-to-pick-the-right-locator-strategy for best locator strategies in order

Yeah but now I have no choice , I inspect element via appium desktop for mac, only xpath @FurbnMax

@MarcSteven Which elemeent are you trying to work on ? Can you expand the left side child node and poin that one and provide full exapnd nodes screenshot. With the above provided screenshot can’t help you as it contain simple classnode.

In child node see if you able to see some elements with XCUIElementTypeStaticText , XCUIElementTypeButton and with name.

No I don’t see it @pothurajtharun

@MarcSteven You can try class chain locators in iOS, Compared to Xpaths class chains locators are fast

**/XCUIElementTypeApplication(`name contains “8”`)/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther