Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 351
nirsky Avatar asked Jul 19 '26 15:07

nirsky


1 Answers

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"]
like image 194
JosephL Avatar answered Jul 21 '26 05:07

JosephL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!