Search code examples
mobileui-automationappium-ios

click on button using text appears on the button


i am trying to click on a button ('Next'/ 'OK' / 'Cancel') using text appear on the button for iOS app in Appium (as these buttons are common through out the application) , is there any way to use the label of the button and by using class chain strategy or iOS Predicate String Strategy click on it. (NOTE: without using Xpath )

I am looking for something like , where i will only pass button name.

def clickOnButton("Next"):

i have tried driver.findElementByIosNsPredicate(XCUIElementTypeWindow[label]).click()


Solution

  • If you want to click UIAButton element with Next label text you can try to build iOSPredicate this way:

    driver.findElementByIosNsPredicate("type == 'UIAButton' AND label CONTAINS 'Next'").click();