【问题标题】:How to scroll down a page如何向下滚动页面
【发布时间】:2015-01-19 09:52:21
【问题描述】:

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

【问题讨论】:

  • 您能否添加一些有关您的自动化的详细信息,例如正在使用的操作系统、自动化应用程序操作系统、您正在使用的 appium 版本等
  • 我正在为安卓应用创建脚本,appium版本是AppiumForWindows-1.2.4.1
  • 我能够使用以下代码向下滚动,WebElement element = driver.findElement(By.className("android.widget.ScrollView")); HashMap arguments = new HashMap();arguments.put("element", ((RemoteWebElement) element).getId()); ((JavascriptExecutor) 驱动程序).executeScript("mobile: scrollTo", arguments);但得到异常信息:[debug] 以错误响应客户端:{"status":13,"value":{"message":"处理命令时发生未知的服务器端错误。","origValue":"无法将元素滚动到视图中:
  • @PramodKumarG 你有任何滚动解决方案吗?我也面临同样的问题
  • @testing,我的问题解决了,正如我在下面的答案中提到的那样

标签: javascript selenium-webdriver appium


【解决方案1】:

我通过下面的代码让它工作了。

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

【讨论】:

  • 我已尝试使用您上面提到的代码,但我收到异常为** org.openqa.selenium.WebDriverException:尚未实现。**,我正在使用 Appium Java 客户端 - 2.2 和 Selenium 版本 2.45。你能帮我解决这个问题吗?
  • 我使用了 selenium 2.44 版和 java 客户端 2.1.0。尝试在设备中运行脚本。我让它在设备中运行。
【解决方案2】:
   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 做任何适当的滚动。至少,我没有找到任何东西。

【讨论】:

  • 当然是迟到的反应,但是,在 iOS 的 Appium 中,大多数涉及 driver.Scroll 的事情都是完全垃圾并且不起作用。此代码将向下滚动,您可以通过将其放入 for 循环来指定希望它滚动多少次。唯一的缺点是它是一个非特定的代码。同样,这段代码来自他们的 github 答案之一,正如我所提到的,Appium 无法为 iOS 做任何适当的滚动。至少,我没有找到任何东西。
  • 啊,明白了。我将在当天晚些时候编辑它,目前正在工作。但我相信评论也能解决问题。
【解决方案3】:

在最近的更新 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

【讨论】:

    【解决方案4】:
    MobileElement radioGroup = (MobileElement) wd.findElementByAndroidUIAutomator("
        new UiScrollable(new UiSelector().resourceId(\"+<listview_id>+\"))
            .scrollIntoView(new UiSelector().text(\"+<your_text>+\"));
    ");
    radioGroup.click();
    

    Manidroid 的方法非常适合我

    【讨论】:

      猜你喜欢
      • 2012-02-05
      • 2014-10-02
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多