Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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

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

I have tried the following but with no success:

app.links["facebook_sharing"].tap()

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

Thanks!

like image 594
Audible Avatar asked Feb 16 '16 21:02

Audible


1 Answers

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 Inspector.app 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?

like image 192
Joe Masilotti Avatar answered Sep 18 '22 10:09

Joe Masilotti