5

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 2

6

Objective-C

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *customView = app.otherElements[@"view_identifier"];

Swift

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

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"] }()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.