Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find elements in an UIWebView

I want to write an UI automation test that log in by using Google. The webview is embedded in the app. In Earlgrey, how can I select a text field or a button of a web view. Thanks

like image 581
sahara108 Avatar asked Mar 06 '26 02:03

sahara108


1 Answers

EarlGrey provides a great log of the UI hierarchy when a test fails. My suggestion is to write a test that navigates to the login view, and then force EarlGrey to fail. Then in the log, look for the elements you need. You should see something like:

--<WebAccessibilityObjectWrapper:0x7fbca2422fb0; AX=Y; AX.value='Email'; AX.frame={{72, 145}, {270, 38}}; AX.activationPoint={207, 164}; AX.traits='UIAccessibilityTraitNone'; AX.focused='Y'>
--<WebAccessibilityObjectWrapper:0x7fbca4e82360; AX=Y; AX.value='Password'; AX.frame={{72, 201}, {270, 38}}; AX.activationPoint={207, 220}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'>

From this log you can see that the two elements are accessible via:

EarlGrey().selectElementWithMatcher(grey_accessibilityValue("Email"))
EarlGrey().selectElementWithMatcher(grey_accessibilityValue("Password"))
like image 187
Wilson Avatar answered Mar 08 '26 18:03

Wilson



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!