Writing tests for an android app that logs into Facebook: UIAutomator can't fill in text in Facebook's username field

主宰稳场 提交于 2019-12-03 22:46:00

I didn't try this against a Facebook login page, but I was able to do this on a different page I created.

I was able to use both UIObject and UIObject2 to location an input box in a web form using the EditText class. I was able to both to set the text in the input box using setText(), but I was not able to read it out with getText().

Selecting HTML input forms requires some care. The only way you can reliably select a specific input is by using instance() to find the n'th indexed field. This means you should probably be limiting the scope of your searches to the WebView parent object (otherwise some other EditText on the screen might offset everything).

Another thing you need to look out for is the load time of the WebView. It's not going to happen instantaneously, so you will need to wait some reasonable amount of time to let the page load.

Here is a bit of sample code that let me find the second input box on a HTML page and put text into it:

UiObject input = mDevice.findObject(new UiSelector()
    .instance(1)
    .className(EditText.class));
input.setText("text");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!