title: iPhone - UI Automation - Type with UIAKeyboard
body: <p>I use <code>UIAutomation</code> to test my iPhone app.<br>
  My app has a <code>UISearchBar</code>, after I made it focused,<br>
  this line of script shows that the app now has 2 <code>UIAWindow</code>.</p>
  
  <pre><code>UIATarget.localTarget().frontMostApp().logElementTree();
  </code></pre>
  
  <p>The second <code>UIAWindow</code> has <code>UIAKeyboard</code> as a child.</p>
  
  <p><img src="https://i.stack.imgur.com/OIwLy.png" alt="enter image description here"></p>
  
  <p>Do you know how to get a reference of the second <code>UIAWindow</code>, so I could get a reference to the <code>UIAKeyboard</code>?</p>
  
  <p>I've tried   </p>
  
  <pre><code>UIATarget.localTarget().frontMostApp().mainwindow()[1].keyboard().key()["Q"].tap();
  </code></pre>
  
  <p>but it doesn't work.</p>
  
  <p><strong>EDIT 1:</strong><br>
  I use this line to get reference of the Keyboard. It works.  </p>
  
  <pre><code>UIATarget.localTarget().frontMostApp().windows()[1].logElementTree();
  </code></pre>
  
  <p>but when I tried to type something with the keyboard:  </p>
  
  <pre><code>UIATarget.localTarget().frontMostApp().keyboard().typeString("Hello world");
  </code></pre>
  
  <p>or</p>
  
  <pre><code>UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap; 
  </code></pre>
  
  <p>but they don't work.</p>
  
  <p><strong>Do you know how to type some thing with the keyboard?</strong></p>
  
  <hr>
  
  <p><strong>EDIT:</strong> 
  (just to let you guys know how to make the UIAKeyboard works for you) </p>
  
  <hr>
  
  <p>UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap;<br>
  <strong>doesn't work</strong><br>
  UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap();<br>
  <strong>works</strong></p>
  
  <p>and<br>
  UIATarget.localTarget().frontMostApp().keyboard().typeString("This is a message");<br>
  <strong>works</strong></p>