Android 具有两个listview时控制滚动视图
我正在使用uiautomator打开WiFi交换机,然后连接到WiFi AP。Android 具有两个listview时控制滚动视图,android,android-uiautomator,Android,Android Uiautomator,我正在使用uiautomator打开WiFi交换机,然后连接到WiFi AP。 我想做的是: 打开WiFi 连接到WiFi AP 但问题是tablet中的设置页面有两个listview。 打开WiFi时,我需要控制左侧列表视图。 然后,我需要控制正确的listview以连接到我的WiFi AP 我需要滚动浏览所有listview项目,但我始终无法这样做。 我确实尝试按实例(0)和实例(1)指定listview,但有时会失败 代码如下: public void TurnOn() { try
我想做的是:
打开WiFi时,我需要控制左侧列表视图。
然后,我需要控制正确的listview以连接到我的WiFi AP 我需要滚动浏览所有listview项目,但我始终无法这样做。
我确实尝试按实例(0)和实例(1)指定listview,但有时会失败 代码如下:
public void TurnOn()
{
try {
UiScrollable settingsList = new UiScrollable(new UiSelector().className(android.widget.ListView.class.getName()).instance(0).scrollable(true));
UiObject btItem = settingsList.getChildByText(new UiSelector().className(android.widget.LinearLayout.class.getName()),"Wi-Fi", true);
UiObject btSwitch = btItem.getChild(new UiSelector().className(android.widget.Switch.class.getName()));
if(!btSwitch.isChecked())
{
btSwitch.click();
sleep(3000);
}
else System.out.println("Wifi is already enabled");
} catch (UiObjectNotFoundException e) {
System.out.println("Can't find the Wi-Fi switch");
}
}
public void ConnectAP()//No password Ap
{
UiScrollable wifiList = new UiScrollable(new UiSelector().className(android.widget.ListView.class.getName()).instance(1).scrollable(true));
if(!wifiList.exists()) wifiList = new UiScrollable(new UiSelector().scrollable(true));
else System.out.println("Its tablet");
UiSelector selector = new UiSelector().className(android.widget.RelativeLayout.class.getName());
UiObject btItem = null;
int maxSearchSwipes = wifiList.getMaxSearchSwipes();
for (int i = 0; i < maxSearchSwipes && i<10; i++)
{
try {
btItem = wifiList.getChildByText(selector, "Guest");
if(btItem.getChildCount()==2) System.out.println("Wifi is already connected to Guest AP or not in range.");
else {
btItem.clickAndWaitForNewWindow();
sleep(3000);
}
break;
} catch (UiObjectNotFoundException e) { //Do nothing
}
for (int j = 0; j < i; j++){
try {
wifiList.scrollForward();
} catch (UiObjectNotFoundException e) {
System.out.println("Can't scrollForward");
}
}
}
if(btItem == null) System.out.println("Can't find Guest AP.");
}
public void开启()
{
试一试{
UiScrollable settingsList=新的UiScrollable(新的UiSelector().className(android.widget.ListView.class.getName()).instance(0.scrollable(true));
UiObject btItem=settingsList.getChildByText(新UiSelector().className(android.widget.LinearLayout.class.getName()),“Wi-Fi”,true);
UiObject btSwitch=btItem.getChild(新的UiSelector().className(android.widget.Switch.class.getName());
如果(!btSwitch.isChecked())
{
btSwitch.click();
睡眠(3000);
}
else System.out.println(“已启用Wifi”);
}捕获(UIObjectNotFounde异常){
System.out.println(“找不到Wi-Fi开关”);
}
}
public void ConnectAP()//无密码Ap
{
UiScrollable wifiList=new UiScrollable(new UiSelector().className(android.widget.ListView.class.getName()).instance(1.scrollable(true));
如果(!wifiList.exists())wifiList=new-UiScrollable(new-UiSelector().scrollable(true));
else System.out.println(“其平板电脑”);
UiSelector selector=new UiSelector().className(android.widget.RelativeLayout.class.getName());
UiObject btItem=null;
int maxSearchSwipes=wifiList.getMaxSearchSwipes();
对于(int i=0;i
更改原始代码
UiScrollable wifiList = new UiScrollable(new UiSelector().className(android.widget.ListView.class.getName()).instance(1).scrollable(true));
进入
而且它有效
UiScrollable wifiList = new UiScrollable(new UiSelector().className(android.widget.ListView.class.getName()).instance(1));