How to enter text into a textfield in a web view u

2019-05-22 14:17发布

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?

2条回答
贼婆χ
2楼-- · 2019-05-22 14:31

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.

查看更多
叼着烟拽天下
3楼-- · 2019-05-22 14:37

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.

查看更多
登录 后发表回答