user1733504
user1733504

Reputation: 21

iOS UIAutomation Cannot Find Search Bar

I want to use the UIAutomation tool in Instruments to simulate some actions. But I cannot find the search bar. The search bar is under a navigation bar and above a table view.

I also set :

self.searchBar.isAccessibilityElement = YES;
self.searchBar.accessibilityLabel = @"Search Bar";

But still cannot find it.

Upvotes: 1

Views: 255

Answers (2)

SimpleApp
SimpleApp

Reputation: 546

Same problem here. I have noticed that when you use logElementTree on Navigation bar the SearchBar does not have name property set.

code inside the script:

var navigationBar = UIATarget.localTarget().frontMostApp().navigationBar();
navigationBar.logElementTree();

Result I get

UIANavigationBar: name:Gallery rect:{{0, 20}, {320, 44}}
  UIASearchBar: value: rect:{{824, 28}, {84, 28}}
  UIAButton: name:Camera rect:{{212, 27}, {42, 30}}

Notice that Button has name "Camera" and and search bar does not. This is why you cannot access SearchBar by using its name. I guess it is a bug?

Upvotes: 0

Peter Zhou
Peter Zhou

Reputation: 4241

Try this:

var target = UIATarget.localTarget();

var app = target.frontMostApp();

var window = app.mainWindow();

var searchBar = window.searchBars()[0];

searchBar.tap();

If this does not work, I can print the elementTree of the mainWindow of your app:

window.logElementTree();

This will log all the UI elements inside the window of your app. You should look for UIASearchBar.

Upvotes: 1

Related Questions