How to enter text into a textfield in a web view using UIAutomation

来源:互联网 发布:网络维护基本知识 编辑:程序博客网 时间:2024/06/05 23:44
up vote1down votefavorite

My iOS app has a log-in page with username and password textfields. These text fields are in a web view. I am trying to automate the log-in process with UIAutomation. I know that working with content in a web view with UIAutomation is tricky. I am able to tap into the text fields using target.tap({x:100, y:200}); but I want to have UIAutomation enter text after the field has been tapped. How can I achieve this?

shareimprove this question
 

2 Answers

activeoldestvotes
up vote2down vote

You can do something like:

  1. Get the reference to the webview

    var webView=window.scrollViews()[0].webViews()[0];
  2. Tap the textView that you want to edit:

    webView.textFields()[0].tap();
  3. Use the keyboard

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

You can use: webView.logElementTree() to find out your webview.

shareimprove this answer
 
 
This works. It's how I do it, although I have my own little framework to make it easier. –  Nick Turner Oct 14 '13 at 14:24
 
One important caveat - you need to make sure you disable the hardware keyboard, or the software keyboard will never show up Hardware ➜ Keyboard ➜ Connect Hardware Keyboard (Toggle to OFF) Also, I seem to need a delay between the tap() and typeString() –  stephan.com Feb 10 at 14:55 
up vote0down vote

Yes this is quite possible but instead of going through the position of the text field, I'd suggest going through the id/name of the text field. Another approach is to traverse the application window. 

Try following this apple's documentation - http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

This will give you a head start and many other ideas. 

shareimprove this answer
 
 
I'd like to do this, but any of the methods available (such as withName()) do not seem to work with textfields within UIWebView's. Any suggestions? –  rdougan Jul 25 '13 at 22:12
0 0
原创粉丝点击