Search code examples
javascriptios-ui-automation

Identifying a cell in UIAutomation with name


I am trying how to identify a cell in a table view, using name using UIAutomation framework. This is a screenshot from editor view of instruments.

enter image description here

I tried the following approaches but didn't succeed yet. What's is the correct or good approach. In general does withName work with any UIAElement?

  1. mainWindow().withName("11:00 AM")
  2. target.frontMostApp().mainWindow().tableViews()[0].cells()1.tableViews()[0].cells()["11:00 am"]

Note that identifying the element with hard coded position works. Like below

target.frontMostApp().mainWindow().tableViews()[0].cells().tableViews()[0].cells()[2]

withName is mentioned in apple documentation - http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIAElementClassReference/UIAElement/UIAElement.html#//apple_ref/javascript/cl/UIAElement#withName


Solution

  • For clarification, the withName() method on UIAElement is a test to see if the element has that name or not. It returns the element if so, or returns a UIAElementNil if not.

    What you're thinking of is withName() on UIAElementArray, which filters the result of the element array to only those with the given name.

    You called withName() on the window, which won't work. These query methods do not do a deep traversal of the element tree to find things. You need to do the traversing yourself like you're doing in line 2.

    I'm not quite sure why it's broken, though. It looks like you're traversing correctly. My hunch is that the name may be hiding extra whitespace characters or unicode in it that the simple string "11:00 am" doesn't match.

    I have a couple suggestions to track this down. Create an intermediate variable for your inner table view. It'll be easier for me to type these suggestions.

    var innerTableView = target.frontMostApp().mainWindow().tableViews()[0].cells().tableViews()[0];
    

    Now try these two suggestions and let me know what it says:

    1. Log the full text of the name of the second cell to see what it is: UIALogger.logMessage("Name is '" + innerTableView.cells()[2].name() + "'");
    2. And if that doesn't help you figure it out, then try matching with a predicate: innerTableView.cells().firstWithPredicate("name contains '11:00 am'").logElement();

    What happens when you run either of those suggestions?