'The custom view added in the WKWebview is not listed during UITesting

I have a UITableview with the below view hierarchy.

UIViewController
  |--UITableView
     |--WKWebview
        |--ScrollView
           |--UIView

The UIView is added once the Webview load is completed and the view appeared properly in the UI. When I run the UITestcases the dynamically added content is not listed during the UITesting.

The below approaches are tried and didn't work.

  • Set isAccessibilityElement false to all the views in the mentioned hierarchy
  • print the app.debugDescription the newly added view contents are not displayed
  • print the XCUIApplication() and here also the newly added view contents are not displayed
  • added the accessibilityIdentifier to all the views the newly added contents are not listed

Not sure whether this is expected behavior or am I doing something wrong here in adding the contents.

Subview code:

[tableViewCell.webView.scrollView addSubview:customView]

Help Appreciated



Solution 1:[1]

The issue is fixed by adding the custom view to the accessibility elements list.

[self.view setAccessibilityElements:@[customView]];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raghav