title: Find parent or sibling with Xcode UI testing
body: <p>I am working with UITableViews and I would like to find the cell that corresponds to a control or static text inside the cell.</p>
  
  <p>More generally, a good way to find any parent or sibling of a given element would be great to know.</p>
  
  <p>Right now I'm just looping through cells until I find the correct one, which I would like to avoid. I've tried using <code>app.tables.cells.containingPredicate</code>, but haven't had any luck. </p>
  
  <pre><code>let pred = NSPredicate { (element, bindings: [String : AnyObject]?) -&gt; Bool in
        return element.staticTexts["My Text"].exists
  }
  let cells = app.tables.cells.containingPredicate(pred)
  </code></pre>
  
  <p>The element passed to the predicate block is an XCElementSnapshot which has no staticTexts.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>James is correct, the containingType:identifier: method works great.</p>
  
  <p>In swift, it looks like this</p>
  
  <pre><code>let cell = app.tables.cells.containingType(.StaticText, identifier: "My Text")
  </code></pre>
  
  <p>Where the identifier in the method signature does NOT correspond to the element's identifier property, rather it is simply the regular way you would access an element by text in brackets. </p>
  
  <pre><code>app.cells.staticTexts["My Text"] 
  </code></pre>