-2
 app.otherElements["the-lab-page"].children(matching: .image)["TheLab_Moon"]

How to find the loctor or identifier in XCUITEST Framework, it is single element I used all types of combinations such as

 app.scrollViews.matching(identifier: "TheLab_Moon")


 app.otherElements.matching(identifier: "TheLab_Moon")
  • Can you be more specific? Are you expecting this to match multiple elements? Strictly one? What’s the problem you are facing? – Mike Collins Mar 21 '22 at 14:47
  • Only one element i am trying to match , Also I am not able to click on the particular elements , i used all types of elements such as other elements – Ankit Gupta Mar 21 '22 at 22:18
  • Can you please provide the `XCUIApplication().debugDescription` of your application when in debug? It’s anyone’s guess what type of element this is. – Mike Collins Mar 22 '22 at 16:07

1 Answers1

0

Without knowing the UI hierarchy of your application (this will be very important as you move forward with your testing), the least efficient way of finding an element with a particular identifier is the following:

XCUIApplication().descendants(matching: .any).matching(NSPredicate(format: "identifier == 'TheLab_Moon'")).firstMatch

Mike Collins
  • 4,108
  • 1
  • 21
  • 28
  • Hey Mate , This is the below hierarchy in the debug mode. `let app = XCUIApplication() let moonbackgroundimageImage = app.otherElements["the-lab-page"].children(matching: .image)["moonBackgroundImage"]` – Ankit Gupta Mar 23 '22 at 02:04
  • That appears to be your test code, not the output of debugging. See my comment on your original question to return the app’s hierarchy. – Mike Collins Mar 23 '22 at 04:02