您的位置:首页 > 产品设计 > UI/UE

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

2015-04-22 23:06 633 查看
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?

ios iphone uiwebview ui-automation ios-ui-automation
shareimprove
this question
edited Oct
28 '13 at 14:36





halakala

709517

asked Feb 7 '13 at 20:50





Edwin Quan

63

add
a comment


2 Answers

activeoldestvotes

up vote2down
vote
You can do something like:

Get the reference to the webview
var webView=window.scrollViews()[0].webViews()[0];


Tap the textView that you want to edit:
webView.textFields()[0].tap();


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


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

shareimprove
this answer
edited Jul
17 '13 at 17:01




Alois Mahdal

2,42111746

answered Jul 17 '13 at 16:33





Felix

1,049911

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
add
a comment
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
answered Mar 3 '13 at 1:06





satyajit

4091922

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐