UI Automation: Access UIViews inside UIScrollView

2019-05-20 04:23发布

Is there a way to access, using JavaScript with UI Automation tests, the UIViews inside an UIScrollView? Since the UIScrollView doesn't give me away to set if it has accessibility or not, I would like to know if it is possible to do that.

The structure in the XIB:

enter image description here

I can see everything on the instrument's log, except the UIScrollView and the UIViews inside of it.

Thanks.

1条回答
爷、活的狠高调
2楼-- · 2019-05-20 04:53

I was able to access the interior of my Scroll View. What I was doing wrong:

  • Setting accessibility to my root view.
  • Setting accessibility to my Adjusted view.

After removing that, I was able my doing this:

var window = UIATarget.localTarget().frontMostApp().mainWindow(); 
window.logElementTree();

To see all the UIViews inside my UIScrollView. To access one of the buttons:

 var scrollView = window.scrollViews()[0];
 var button=scrollView.buttons()["showMeStuff"];
 button.tap();

PS: Is also possible to define the accessibility of an UIScrollView by doing the following:

  scrollView.isAccessibilityElement = YES;
  scrollView.accessibilityLabel = @"someScrollView";
查看更多
登录 后发表回答