我想向下滚动到页面底部,然后执行某个操作。使用
uiautomator
,我获得了以下内容:
index=2,
resource-id=com.manoramaonline.arogyam:id/pager,class=android.support.v4.view.ViewPager,
scrollable=true.
我尝试使用下面的代码来做到这一点:
JavascriptExecutor js = (JavascriptExecutor) driver;
RemoteWebElement element =(RemoteWebElement)driver.findElement(By.xpath("//android.support.v4.view.ViewPager[@resource-id='com.manoramaonline.arogyam:id/pager']"));
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
// This is where the error is
scrollObject.put("element", element.getId());
js.executeScript("mobile: scroll", scrollObject);
我通过以下代码让它工作。
WebElement element = driver.findElement(By.className("android.widget.ScrollView"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
// actions.click();
actions.perform();
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
此代码将向下滚动,您可以通过将其放入 for 循环来指定您希望其滚动的次数。唯一的缺点是它是一个非特定代码。同样,这段代码来自他们的 github 答案之一,正如我提到的,Appium 无法为 iOS 进行任何正确的滚动。至少,我没有找到任何东西。
在最近的更新中,appium“mobile:scroll”已弃用,以下代码将起作用,视频将帮助您实现。
滚动到文本:
MobileElement radioGroup = (MobileElement) wd
.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"
".resourceId(\"+<listview_id>+\")).scrollIntoView("
"new UiSelector().text(\"+<your_text>+\"));");
radioGroup.click();
此链接将为您提供帮助:https://www.youtube.com/watch?v=bT3tqaLNn-Y
MobileElement radioGroup = (MobileElement) wd.findElementByAndroidUIAutomator("
new UiScrollable(new UiSelector().resourceId(\"+<listview_id>+\"))
.scrollIntoView(new UiSelector().text(\"+<your_text>+\"));
");
radioGroup.click();
Manidroid的方法非常适合我