title: Xcode UITest sometimes does not find property of XCUIElement
body: <p>In my UI tests, the frame property of some <code>XCUIElement</code> are found, but not of others.<br>
  The accessibility identifiers used below are set in storyboard, and <code>app</code> is initialised in <code>setUp()</code> as <code>XCUIApplication()</code>.  </p>
  
  <p>Here is the storyboard layout:  </p>
  
  <p><a href="https://i.stack.imgur.com/fieix.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fieix.png" alt="enter image description here"></a></p>
  
  <p>The two UI elements used in the test are <em>Text Field</em> and <em>Add Button</em>.  </p>
  
  <p>Here is the relevant code:  </p>
  
  <pre><code>func test() {
      // given
      let mainViewNavigationBar = app.navigationBars[„NavBar“]
      let navBarHeight = mainViewNavigationBar.frame.size.height
      print("navBarHeight: \(navBarHeight)") // is printed out correctly
  
      let addShoppingItemTextField = app.textFields["TextField"]
      let textFieldHeight = addShoppingItemTextField.frame.size.height // error breakpoint here
      print("textFieldHeight: \(textFieldHeight)")
  }
  </code></pre>
  
  <p>The test stops at an error breakpoint at the second last line with the following message:  </p>
  
  <pre><code>No matches found for Find: Descendants matching type TextField from input {(
      Application, 0x60000019f070, pid: 13114, label: ‚xxx‘
  )}
  </code></pre>
  
  <p>I do not understand why the <code>frame</code> property, which should be defined for all <code>XCUIElement</code>, is found in the first case, but not in the second.  </p>
  
  <p><strong>EDIT</strong>  </p>
  
  <p>Oletha pointed out below, that my constant <code>addShoppingItemTextField</code> is an <code>XCUIElementQuery</code> that should be resolved when I try to read the <code>frame</code> property of the <code>textField</code>.<br>
  Indeed, when the program stops at the test error breakpoint and I print its description, I get  </p>
  
  <pre><code>Printing description of addShoppingItemTextField:
  Query chain:
   →Find: Target Application 0x6080000a6ea0
    ↪︎Find: Descendants matching type TextField
      ↪︎Find: Elements matching predicate '"TextField" IN identifiers'  
  </code></pre>
  
  <p>But the find fails, although Accessibility is enabled, and the Accessibility Identifier is set to <code>TextField</code>:  </p>
  
  <p><a href="https://i.stack.imgur.com/gtNMP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gtNMP.png" alt="enter image description here"></a>  </p>
  
  <p>I also inserted in the app  </p>
  
  <pre><code>print(textField.accessibilityIdentifier!)
  </code></pre>
  
  <p>in <code>viewDidLoad()</code>, and it printed out <code>TextField</code> correctly.</p>
  
  <p>As a workaround, I set the test to recording, and tapped the <code>textField</code>. This created code for the access to the <code>textField</code>. I then replaced let <code>addShoppingItemTextField = app.textFields["TextField"]</code> by (the right side was generated by the recording):  </p>
  
  <pre><code>let addShoppingItemTextField = app.otherElements.containing(.navigationBar, identifier:"WatchNotOK")
  .children(matching: .other).element.children(matching: .other).element
  .children(matching: .other).element
  </code></pre>
  
  <p>And now the code works without errors.  </p>
  
  <p>So it seems to me that the query for the accessibility identifier of a <code>textField</code> does not work correctly.</p>
  
  <p><strong>EDIT 2</strong>  </p>
  
  <p>I give up: Without changing anything in the storyboard, the test now stops with the same test error (<em>No matches found for Find: Elements matching predicate '"WatchNotOK" IN identifiers‘</em>) at the line <code>let navBarHeight = mainViewNavigationBar.frame.size.height</code>. This did work all the time.<br>
  This indicates to me that Xcode UI tests are broken.</p>