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?
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.
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.
来源:https://stackoverflow.com/questions/14760746/how-to-enter-text-into-a-textfield-in-a-web-view-using-uiautomation