0

I want to access callout views and do some UIAutomation on those views. I'm able to click on map markers/annotations but not able to access the callout view. The following code used to tap on the marker:

let marker = app.otherElements.matching(identifier: "mapMarker").element(boundby: 0)
marker.tap();

After this, I'm getting the callout view of the respected marker/annotation. I need to access that callout. Please suggest me on this.

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

You should create a breakpoint after the callout is snown, then type po print(app.debugDescription) (or simply po app in XCode 11) in lldb in order to view the whole hierarchy of UI elements.

Locate the needed element and access it further in code.

Also, consider rewriting your marker code in a shorter way:

let marker = app.otherElements["mapMarker"].firstMatch

Please notice firstMatch aborts search of elements after it found the first one.

Drop firstMatch, if you want to check that the element is unique

let marker = app.otherElements["mapMarker"]

Roman Zakharov
  • 2,185
  • 8
  • 19
  • I already checked that above po print(app.debugDescription). Callout info is not displaying the UI hierarchy. – Raghu Dandu Oct 09 '19 at 10:21
  • The view should be an accessibility element in order to appear in this hierarchy. This requires to adjust the app code appropriately. Please refer to https://developer.apple.com/documentation/uikit/accessibility/supporting_voiceover_in_your_app – Roman Zakharov Oct 09 '19 at 10:47
  • This syntax: `app.otherElements["mapMarker"].firstMatch`: can result in flaky uitests if the model providing the view is backed via a network call. The ["mapMarker"] filter mechanism will only try three times before giving up. You might want to write a method that uses an expectation to wait for the expected elements to appear instead – ablarg Oct 16 '19 at 21:40
0

Same as Smart Monkey said, but to add more code based off the comment from ablarg:

Ex: "mapMarker" being the accessibility ID for the element

    let mapMarker = app.maps.otherElements["mapMarker"].firstMatch
    let mapMarkerExists = mapMarker.waitForExistence(timeout: 3)
    if mapMarkerExists {
      mapMarker.tap()
  }

waitForExistence(timeout:) returns a bool, so if the element appears before the timeout expires (it finds the element) take action (tap) on the element.

Make sure the element is enabled for accessibility and has the accessibility ID set.

Kimothy
  • 11
  • 3