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

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?

share improve this question
 

2 Answers

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.

share improve 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 

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. 

share improve 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值