swiftxcodecoded-ui-testsxcuitest

Access last element in XCUIElement


In my UI Test, i have this XCUIElement :

XCUIApplication().staticTexts["SUBMIT ORDER"]

When i make a print debugDescription :

po print(XCUIApplication().staticTexts["SUBMIT ORDER"].debugDescription)

There is two element matching :

Find: Elements matching predicate '"SUBMIT ORDER" IN identifiers'
      Output: {
        StaticText, {{0.0, 623.0}, {375.0, 44.0}}, label: 'SUBMIT ORDER'
        StaticText, {{0.0, 623.0}, {375.0, 44.0}}, label: 'SUBMIT ORDER'
      }

My question is : How can i make a .tap() on the last element only ?


Solution

  • You can do it using :

    XCUIApplication().staticTexts.matching(identifier: "SUBMIT ORDER").allElementsBoundByIndex.last