title: How can I verify the name of a label in a table view using Instruments on iOS?
body: <p>I'm using the Xcode "Instruments" tool to build automation for an iOS application and I need to verify that the label for an entry I've created in my app is correct. </p>
  
  <p>The code listed below is, for some reason, not resulting in a solid pass or fail. Rather, when it runs, I get an "Issue" warning in the log and the test exits without explicitly closing. </p>
  
  <p>I want to change my tests so that I check for the label name that I know is getting created, because I can see it with the AccessibilityViewer after my automation runs.</p>
  
  <p>If the label is correct, then I want to log the test as a pass. </p>
  
  <p>I've used <code>UIATarget.localTarget().logElementTree()</code> to map my element tree and I've used the AccessibilityInspector to verify the name of my label after my entry has been created. Trouble is, I just can't seem to get the syntax for verifying this correct. </p>
  
  <p>My Accessibility Inspector has verified that the label name is: MyDogs! and it has the traits of Static Text and gives the Frame of {{114, 0},{166,480}}</p>
  
  <p>By looking at the element tree--which I wish I could paste in here, it looks like the label would be found along this path:</p>
  
  <pre><code>\Target
  -+
  --\Application
  ---+
  ----\Window
  -----+
  ------\TableView
  -------+
  --------\TableCell: name:MyDogs! rect:{0, 40},{480,166}}
  ---------|UIAStaticText: name:MyDogs! value:MyDogs! rect:{{0, 40},{480, 166}}
  ---------|UIAButton: name:story list share rect:{{439, 41},{33, 28}}
  </code></pre>
  
  <p>Can anyone tell me how the heck to verify this label?</p>
  
  <p>My current code looks like this (but is not checking for the label--because I don't know how to):</p>
  
  <pre><code>var testName = "LoginCreateEntry";
  
  //Start test logging
  UIALogger.logStart(testName);
  
  //This is supposed to target the entry that my automation has created.
  //The flow goes, run the automation that creates the entry, then verify that the entry
  //got created as expected and is visible to the user in the iPhone interface.
  
      var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].value(); 
  
      var entryName = "My Dogs!";
  
  //Do a bunch of UI automation here to create my entry, which results in the entry
  //appearing in the mainWindow with the label: My Dogs!
  
  //If myEntry evaluates to true, then call this test a pass.
  
  if (myEntry === entryName) {    
  UIALogger.logMessage("My entry was created!");
  
      //Mark the test as a PASS
      UIALogger.logPass(testName);
  }
  else {
  
      UIALogger.logMessage("My entry was not created!");
  
      //Mark the test as a FAIL
      UIALogger.logFail(testName); 
      }
  
  //End test
  </code></pre>
  
  <p>Any feedback or help would be most appreciated!!</p>
  
  <p>---------------------------------UPDATE--------------------------------------
  <BR>
  Thanks all for your help! I actually got the value of the title and will display my solution below. But I CANNOT get the pass/fail logging functionality to work correctly no matter what I do--and the issue has been <a href="https://stackoverflow.com/questions/14865999/instruments-automation-tool-script-ended-without-explicitly-closing-this-test/15259630#15259630">encountered by others</a> as well. I keep getting the enraging</p>
  
  <p><code>Issue: Script ended without explicting closing this test</code> </p>
  
  <p>message at the end of my tests. I'm becoming convinced it's a bug with Instruments. </p>
  
  <p>Here's my updated test:</p>
  
  <pre><code>var target = UIATarget.localTarget();
  var app = UIATarget.localTarget().frontMostApp();
  
  var testName = "LoginCreateEntry";
  
  //Start test logging
  UIALogger.logStart( testName );
  
  //Do lots of gui automation stuff here to create the entry which will appear in my app interface.
  //I want to verify that the title I gave the entry matches what appears in the app interface
  
  var window = app.mainWindow();
  var tableView = window.tableViews()[0];
  var tableGroup = tableView.groups()[0];
  var entryName = "My Dogs!";
  
  var myEntry = tableView.cells()[0].name(); //&lt;-- This is what I needed!!!
  
  UIALogger.logMessage("My Story Title: " + myEntry); //Print out entry name in log
  
  if (myEntry === entryName) {    
  
      UIALogger.logMessage("My entry was created!");
  
      //Mark the test as a PASS
      UIALogger.logPass (testName);
  
  } else {
  
      UIALogger.logMessage("My entry was not created!");
  
      //Mark the test as a FAIL
      UIALogger.loFails (testName); 
  
      }
  //End test 
  </code></pre>