appium + java 怎么实现滑动页面到某个元素的位置 · TesterHome
展开全部
public class MyAndroidDriver extends AndroidDriver {
public MyAndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
}
static String UiScrollable(String uiSelector) {
return "new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView("
+ uiSelector + ".instance(0));";
}
/**
* 滑动到某元素
* @param uiScrollables 符合UiScrollable的string串
* @return
*/
public WebElement scrollToElement(String uiScrollables ) {
String uiScrollables = UiScrollable(uiScrollables );
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
return findElementByAndroidUIAutomator(uiScrollables);
}
}
看了AndroidDriver源码中scrollTo方法之后的思路,当然了,这边的uiScrollables 需要构造,例如:new UiSelector().className(\"android.widget.TextView\").textContains(\"测试测试\").resourceId(\"com.xx.xxx:id/package_exchange_textview\")
public MyAndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
}
static String UiScrollable(String uiSelector) {
return "new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView("
+ uiSelector + ".instance(0));";
}
/**
* 滑动到某元素
* @param uiScrollables 符合UiScrollable的string串
* @return
*/
public WebElement scrollToElement(String uiScrollables ) {
String uiScrollables = UiScrollable(uiScrollables );
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
return findElementByAndroidUIAutomator(uiScrollables);
}
}
看了AndroidDriver源码中scrollTo方法之后的思路,当然了,这边的uiScrollables 需要构造,例如:new UiSelector().className(\"android.widget.TextView\").textContains(\"测试测试\").resourceId(\"com.xx.xxx:id/package_exchange_textview\")
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询