Audible Audible - 3 months ago 33
iOS Question

Xcode UI Test - How to Find and tap() an Element Inside a WebView

I am trying to find a way to tap a link with the following HTML structure:

<div id="facebook_sharing"></div>

tag does not have any attributes or text associated with it, just the
tag inside.

I have tried the following but with no success:


Is there a way to find the
tag element and tap on it?



Xcode UI Testing interacts with your app via accessibility. Just like it doesn't have access to the underlying UIKit elements, it doesn't have direct access to the HTML DOM. You cannot expect the framework to know about something in your markup unless that gets exposed to accessibility in some way.

To "see the app as UI Testing does" open Accessibility on your mac. (You can easily find this by searching for it in Spotlight.) Then, hover over the div with your cursor. If you see any of the following attributes set you can query for the element:

  1. accessibilityTitle
  2. accessibilityPlaceholderValue
  3. accessibilityLabel
  4. accessibilityValue

If none of these are set on the a or div elements you should update them yourself. Think of it this way. If someone who is visually impaired uses the site, how will he/she know that he/she can interact with the Facebook link?