Dynamic Locator in iOS App

Hello,

I am having hard time to locate element which is dynamic and changing everyday. Can you please help me to find stable version of the below selectors? I will put xPath, iOSClassChain and ios predicate string versions of same element/

NOTE: “Lina Test Enrollment” and “331” are changing everyday. That is why need to be considered.!!!

-ios class chain: **/XCUIElementTypeButton[label == "Lina Test Enrollment, Due in 331 days"]

-ios predicate string: label == “Lina Test Enrollment, Due in 331 days” AND name == “Lina Test Enrollment, Due in 331 days” AND type == “XCUIElementTypeButton”

xpath: //XCUIElementTypeButton[@name=“Lina Test Enrollment, Due in 331 days”]

Write examples of text yesterday, today and tomorrow

@Aleksei wasnt sure if that was request or not, but sharing different versions based on (I said “Lina Test Enrollment” is dynamic because there might be different names for it, not specifically that one, but number of days is decreasing by 1 each day and affects the locator as well as below):

Yesterday: -ios class chain: **/XCUIElementTypeButton[ label == "Lina Test Enrollment, Due in 332 days" ]
Today: -ios class chain: **/XCUIElementTypeButton[ label == "Lina Test Enrollment, Due in 331 days" ]
Tomorrow: -ios class chain: **/XCUIElementTypeButton[ label == "Lina Test Enrollment, Due in 330 days" ]

@iOSXCUITFindBy(iOSNsPredicate = "type == 'XCUIElementTypeButton' AND label BEGINSWITH 'Lina Test Enrollment, Due in '")
1 Like

@Aleksei you just saved the whole day for me. Thank you champion, appreciate your help

iOS predicates also allow to use LIKE or MATCHES operator in combination with template strings/regexps. Check https://gitee.com/tonybearpan/appium/blob/c2c333b3af0c8f1292768f2e6b52aa658e14a6e6/docs/en/writing-running-appium/ios_predicate.md for more details.

1 Like