Android uiautomator:如何通过索引获取EditText字段?

Android uiautomator:如何通过索引获取EditText字段?,android,testing,automation,android-uiautomator,Android,Testing,Automation,Android Uiautomator,UiSelector允许您通过文本、TextStartWith、contains等获取EditText字段: UiObject obj = new UiObject(new UiSelector().text(text)); 但是,如何获取第二个文本字段?碰巧该字段没有任何文本或描述。如果我这么做的话 UiObject textField = new UiObject(new UiSelector().index(index)); 然后它返回一个字段,该字段不是带有索引的Edi

UiSelector允许您通过文本、TextStartWith、contains等获取EditText字段:

   UiObject obj = new UiObject(new UiSelector().text(text));

但是,如何获取第二个文本字段?碰巧该字段没有任何文本或描述。如果我这么做的话

   UiObject textField = new UiObject(new UiSelector().index(index));
然后它返回一个字段,该字段不是带有索引的EditText

谢谢

试试看

UiObject textField = new UiObject(new UiSelector()
   .className("android.widget.EditText").instance(1)
你可以试试这个-

 UiSelector(). className("android.widget.ImageView") .enabled(true). instance(1). setText("Hola!");


谢谢我以前试过。问题是它不能搜索整个屏幕。i、 例如,如果EditText在UI层次结构中向下三级,则调用UiObject textField=new UiObject(new UiSelector().className(“android.widget.EditText”)。实例(2)将导致异常:testSearch中的错误:com.android.uiautomator.core.UiObjectNotFoundException:UiSelector[CLASS=android.widget.EditText,instance=1]在com.magnet.mobileserver.tests.android.ui.app.TemplateApp.testSearch(TemplateApp.java:44)的com.android.uiautomator.core.UiObject.getText(UiObject.java:481)上,如果您知道资源ID,可以使用它来选择文本字段。
 UiObject editText = new UiObject(new UiSelector(). className("android.widget.EditText"));
 editText.setText("Hola!");