javascript 如何在appium中向下滚动页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27058183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 06:53:17  来源:igfitidea点击:

how to scroll down a page in appium

javascriptselenium-webdriverappium

提问by Tester

I want scroll down to the bottom of page and do some action.Using uiautomatorI have obtained following:

我想向下滚动到页面底部并执行一些操作。使用uiautomator我获得了以下内容:

index=2,
resource-id=com.manoramaonline.arogyam:id/pager,class=android.support.v4.view.ViewPager,
scrollable=true.

Please help me to do this.

请帮我做这件事。

I am trying out with code below . Could anyone point the issue?

我正在尝试使用下面的代码。有人能指出这个问题吗?

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");
//i am getting error for this code
scrollObject.put("element", element.getId());
js.executeScript("mobile: scroll", scrollObject);

回答by Tester

I got it working by following code.

我通过以下代码让它工作。

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

回答by SomeStudent

   JavascriptExecutor js = (JavascriptExecutor) driver;
            HashMap<String, String> scrollObject = new HashMap<String, String>();
            scrollObject.put("direction", "down");
            js.executeScript("mobile: scroll", scrollObject);

This code will scroll downwards, you can specify how many times you wish for it to scroll by placing it into a for loop. Only downside is that it is a nonspecific code. Again, this code is from one of their github answers, and as I mentioned, Appium is incapable of doing any proper scrolls for iOS. At least, I haven't located anything.

此代码将向下滚动,您可以通过将其放入 for 循环来指定希望它滚动的次数。唯一的缺点是它是一个非特定代码。同样,此代码来自他们的 github 答案之一,正如我所提到的,Appium 无法为 iOS 执行任何适当的滚动。至少,我没有找到任何东西。

回答by Mani

In recent update appium "mobile : scroll" deprecated, following code will work and video will help you to implement.

在最近的更新 appium 中“移动:滚动”已弃用,以下代码将起作用,视频将帮助您实现。

Scroll to text :

滚动到文本:

MobileElement radioGroup = (MobileElement) wd

.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"

".resourceId(\"+<listview_id>+\")).scrollIntoView("

"new UiSelector().text(\"+<your_text>+\"));");

radioGroup.click();

This link will help you : https://www.youtube.com/watch?v=bT3tqaLNn-Y

此链接将帮助您:https: //www.youtube.com/watch?v=bT3tqaLNn-Y

回答by Alexandr Shchepkin

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

method from Manidroidworks for me perfectly

Manidroid 的方法非常适合我