iOS - search for a button within a cell with ios Ui Automation

Hey everyone, I need to find a button inside a cell (within a tableView).

Ui Automation recorded the following:

target.frontMostApp().mainWindow().tableViews()[0].cells()["5 July 2015"].tap();

But what I need is the button inside a non-specific cell.

I tried the following but it didnt work.

target.frontMostApp().mainWindow().tableViews()[0].cells().buttons().firstWithPredicate("name = '19 July 2015'");

Any idea whats wrong with it or how should I approach it? Ui Automation selectors are sadly not well documented.

Also, the xpath to the button is as follows (disregard indexes, they are not static).

//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[6]/UIAButton[@name='19 July 2015']

If I had to guess, the problem resides because you are asking for a list of multiple buttons upon multiiple cells. I don’t think that’s going to work.
It’s best to store your cells() as an array, iterate on that array and call buttons() to find what you need. I know it’s not pretty but it’s what I would do.
Happy to provide more guidance of you need
Cheers
Eric

Could you expand on that idea? I’m not sure I understand what you mean.

Also, Ideally I’d just search for the button with name. Since this is a calendar, I scrolled to the wanted month but providing short name + year e.g. (“JUN 2015”). After that, I was going to select a button with a name from the visible elements.

The problem with the above approach was that the searching for the button took a very long time. I’m guessing it’s iterating through all the elements rather than just the visible ones?

If the button you’re looking for ONLY exists in a single UIATableCell as opposed to existing in multiple UIATableCell just call for it directly with this xpath:

//UIAButton[@name='19 July 2015']

Otherwise try this xpath:

//UIATableCell[@name='26 July 2015']]/UIAButton[@name='19 July 2015']

2 Likes

I’ll combine your approach with mine.

  1. Scroll to the month using UIATableCell[@name=“JUN 2015”]
  2. tap on the button using accessibility label (which is the same as name)

The problem that I had with this approach was the duration of the search. Is there any way to restrict the search to only the elements displayed on the screen?