1

How do you access a UIActivityViewController (share / actions sheet) in XCUITest? According to the Accessibility Inspector, t is comprised of several UICollectionViews, which makes it hard to disambiguate the sheet itself.

Querying for XCUIApplication().sheets.count returns 0 when the sheet is presented.

Chase Holland
  • 2,178
  • 19
  • 23

2 Answers2

8

It turns out, when using the view debugger, the sheet is accessible via a somewhat hidden accessibilityIdentifier of ActivityListView (as of Xcode 9.2). It can be accessed with:

XCUIApplication().otherElements["ActivityListView"]

Note that the "Cancel" button is added to the window separately, so it not a child of the activity controller and must be accessed with

XCUIApplication().buttons["Cancel"]
Chase Holland
  • 2,178
  • 19
  • 23
0

Tested on xcode 12.2 with iOS 14.2:

XCUIApplication().otherElements.element(boundBy: 1).buttons.element(boundBy: <insert button index here>).tap()

Possible button index numbers:

  • 0: Cancel
  • 1: Copy
  • 2: Markup
  • 3: Print
  • 4: Save to files
  • This approach I get the following error: `Failed to synthesize event: Failed to scroll to visible (by AX action) Button, error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 3118, elementOrHash.elementID: 4354340448.106. (Underlying Error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 3118, elementOrHash.elementID: 4354340448.106) ` – JCutting8 Jul 25 '21 at 16:01