如何使用UIAutomation在Web视图的文本框中input文本

我的iOS应用程序有一个用户名和密码文本框的login页面。 这些文本字段在Web视图中。 我正在尝试使用UIAutomation自动化login过程。 我知道使用UIAutomation在Web视图中处理内容是非常棘手的。 我可以使用target.tap({x:100, y:200});来点击文本字段target.tap({x:100, y:200}); 但是我想让UIAutomation在点击字段后input文本。 我怎样才能做到这一点?

你可以做一些事情:

  1. 获取对webview的引用

     var webView=window.scrollViews()[0].webViews()[0]; 
  2. 点击你想编辑的textView:

     webView.textFields()[0].tap(); 
  3. 使用键盘

     UIATarget.localTarget().frontMostApp().keyboard().typeString("text"); 

你可以使用: webView.logElementTree()来找出你的webview。

是的,这是很有可能的,但不是通过文本字段的位置,我build议通过文本字段的ID /名称。 另一种方法是遍历应用程序窗口。

尝试下面这个苹果的文档 – http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

这会给你一个开始和许多其他的想法。