Reputation: 3105
Our app is hybrid and contains webview. I'm trying to automate our app using Xcode UI Testing. I was able to locate web buttons using:
let app = XCUIApplication()
app.launch()
let button = app.staticTexts["Button's text"]
But in one of our tests we test localization - meaning the text changes and the static text query is no longer valid. Couldn't find any documentation how to locate an element by his id (or even class name). Any ideas?
Upvotes: 3
Views: 7256
Reputation: 5973
I have had a similar problem trying to fill in text fields in a SFSafariViewController
.
I found that using the aria-label
attribute allowed me to locate elements in the page e.g.
<input role="textbox" aria-label="email" type="email" value="" name="user[email]" id="user_email">
And then in your code to select that element
webViewsQuery.textFields["email"]
Upvotes: 5
Reputation: 505
By id(ui-test code e.g on swift):
app.buttons["yourBtnAccessibilityId"]
this id sets into you app`s code (e.g on obj-c) and should be unique.
yourButton.accessibilityIdentifier = @"yourBtnAccessibilityId";
By class(ui-test code):
app.buttons.elementBoundByIndex(1)
Upvotes: -6