javascript 如何向下滚动页面

jchrr9hc  于 2023-01-24  发布在  Java
关注(0)|答案(4)|浏览(173)

我想向下滚动到页面底部,然后执行一个操作。使用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);
3df52oht

3df52oht1#

我是按照程序运行的。

WebElement element = driver.findElement(By.className("android.widget.ScrollView"));
    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    // actions.click();
    actions.perform();
plupiseo

plupiseo2#

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上不能做任何正确的滚动。至少,我还没有找到任何东西。

nukf8bse

nukf8bse3#

在最近更新的appium“移动的:滚动”已弃用,以下代码将正常工作,视频将帮助您实现。
滚动到文本:

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

h7appiyu

h7appiyu4#

MobileElement radioGroup = (MobileElement) wd.findElementByAndroidUIAutomator("
    new UiScrollable(new UiSelector().resourceId(\"+<listview_id>+\"))
        .scrollIntoView(new UiSelector().text(\"+<your_text>+\"));
");
radioGroup.click();

Manidroid中的方法非常适合我

相关问题