Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an element that contains another element with a static text in iOS UITesting

How to build a query to get an element that contains another element by static text.

Example: Get the first table cell that contains a label with text "cool cell"

I need it because I have different cells and I want to get a cell that contains a specific text. Note that I'm interested to get the cell because I need to make sure that the cell contains another elements. The goal is to make sure that the cell with the title "I'm a cell" has also a label with text "cool"

like image 499
iOSGeek Avatar asked Nov 08 '22 10:11

iOSGeek


1 Answers

Get the first table cell that contains a label with text "cool cell"

How about:

let app = XCUIApplication()
app.cells.containing(.staticText, identifier: "cool cell")

If that's not enough, there's a version of containing that takes NSPredicate:

func containing(_ predicate: NSPredicate) -> XCUIElementQuery
func containing(_ elementType: XCUIElement.ElementType, identifier: String?) -> XCUIElementQuery

Documentation:

Returns a new query for finding elements that contain a descendant matching the specification" which is what you need. [...]

like image 53
Rudolf Adamkovič Avatar answered Nov 13 '22 22:11

Rudolf Adamkovič