Interacting with iOS web views using XCUITest

Aya Akl
1 min readJun 19, 2019

--

I had to work with not only native views inside the mobile app, but also the iOS web views which is a little bit not straight forward to deal with and write UI tests for them like the native views of iOS in XCUITest.

Not like Appium which is easy to switch to Selenium and deal with the web part and then back to Appium to deal with the mobile part, as in my blog post here.

The main pain point in dealing with web views in XCUITest is that you won’t be able to deal with Accessibility Identifiers but with the element label, placeholder or value but unfortunately not with the accessibility identifiers because you don’t have the access to the elements under this web view.

There is a small workaround is to check with your web developer and agree on such label but the main problem will be when you are trying to deal with third part web views like Facebook Login.

So to work with this part, XCUITest can get the web element with two ways:

  1. Find descendants of the web view and find the element by its UI location matching the web element type (TextField, StaticText, Button, etc.).

2. Find descendants of the web view and find the element by using a selector (label, value, or placeholder) and the same as previously matching the web element type.

References:

Apple Documentation on instance method: descendants(matching:)

HAPPY TESTING!

--

--

Aya Akl

#Quality is my thing - Passionate human being who wants to change the world!! #MobileTester #SDET #iOS #Testing