XCUITest detect UIView

Viewed 4020

So in XCUITest I use this code to get a button:

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *button = app.buttons[@"button_identifier"];

getting a tableview using app.tables and image using app.images and so on.

But how can I get a view(UIView)?

2 Answers

For Swift 3 / 4 it would look like:

let app = XCUIApplication()
let custom_view = app.otherElements["view_identifier"]

Also what I like to do is to have a class variable, as I do reuse these views frequently for different tests:

lazy var custom_view: XCUIElement = { return XCUIApplication().otherElements["view_identifier"] }()
Related