在更换地区的时候,需要滑动页面到某个元素的位置,然后选择,,这个要怎么实现呢
给你一个思路(Macaca+Python)
https://testerhome.com/topics/7658
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\")