How to write iOS Class Chain Strategy for Xpath axes?

Can you please help me how to write iOS Class Chain for the below Xpath ?

  1. //XCUIElementTypeStaticText[@name=‘Next’]/following::XCUIElementTypeStaticText[1]

  2. //XCUIElementTypeStaticText[contains(@value,‘What’)]/ancestor::XCUIElementTypeTextView[1]

I’m afraid this is not possible. Class chain locators don’t support axes

Thank you! Please let me know any other alternative methods to achieve above xpath conditions. Xpath is very slow for IOS Appium Test execution.

For the second one I would try something like

**/XCUIElementTypeTextView[$type == 'XCUIElementTypeStaticText' AND value CONTAINS 'What'$]

The first one is more tricky. Most likely it will be necessary to perform several class chain queries, although I’m not quite sure these all are going to be much faster than the single given xpath

What is use of appending $ symbol ?

Thanks for sharing link !

Hi

What is class chain locator for below xpath :
1)//XCUIElementTypeTextField
2)//XCUIElementTypeTextField[1]

@mykola-mokhnach is there a way to achieve for iOS class chain what can be achieved for xpath by using “|”, to basically have two different locators in one?
e.g.: //XCUIElementTypeButton[not(starts-with(@name,“name”))]/XCUIElementTypeStaticText[starts-with(@value,“value”)]|//XCUIElementTypeButton[starts-with(@name,“name”) or starts-with(@label,“label”)]
P.S: Is there an equivalent for iOS class chain of the following xpath condition: [string-length(@value)<=10]

P.S: Is there an equivalent for iOS class chain of the following xpath condition: [string-length(@value)<=10]

You could achieve that with regexes: ios - CoreData predicate: string property length? - Stack Overflow

//XCUIElementTypeButton[not(starts-with(@name,“name”))]/XCUIElementTypeStaticText[starts-with(@value,“value”)]|//XCUIElementTypeButton[starts-with(@name,“name”) or starts-with(@label,“label”)]

I don’t think there is a direct class chain alternative to the above locator

So regarding having two locators in one (like it is possible using xpath), if it is not possible to do it via iOS class chain, what approach can I use to identify buttons by text in the page source, since xpath locators are very very slow?

What about can specify it as [$<predicate_string>$] from examples → Improving Appium iOS automation performance by replacing XPaths | by Sebin Joseph | Medium

Try it @leftty86

oi you mentioned it in 2019 :slight_smile:

If it is only necessary to identify buttons by their attributes and not sibling elements then a simple predicate should be enough

type == 'XCUIElementTypeButton' AND name BEGINSWITH 'name'

I looked over the info from the link, but you can only combine filters for the same element, you can not combine two locators that might point to different elements into one locator. For xpath that is possible only because “|” acts as a logical “or” between two separate locators and allows us to join them into one locator.