nirsky
nirsky

Reputation: 3105

Xcode UI Testing - Finding element in Webview by id

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

Answers (2)

JosephL
JosephL

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

Che
Che

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

Related Questions