如何使用appium驱动程序从上到下滚动Android应用程序页面? [英] How can I scroll an android app page from top to bottom using appium driver?

查看:173
本文介绍了如何使用appium驱动程序从上到下滚动Android应用程序页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我想从上到下滚动一个Android移动应用页面。

  1. I want to scroll an android mobile app page from top to bottom.

我试过以下为滚动定义编码并使用文本单击特定Web元素。它工作正常。

I have tried with below defined coding for scroll and click for specific web element using text. It works fine.




 // method 1
    driver.scrollTo("R");

    // method 2
    driver.ScrollToExact("Top");





  1. 但是我需要从上到下滚动整篇文章页面,而不使用上面的scroll()方法。我尝试使用以下编码,但滚动操作不会发生在我身上。




//滚动到页面底部

// scroll to bottom of an page

((JavascriptExecutor) driver) .executeScript("window.scrollTo(0,
document.body.scrollHeight)"); 





  1. 如何我可以使用appium驱动程序从上到下滚动Android应用程序页面吗?


推荐答案

在这里你需要在循环中使用 text 进行检查,该循环显示在页面底部。如果找到文本而不是中断循环。

Here you need to check everytime with a text in the loop, that appears on the bottom of the page. If the text found than break the loop.

Dimension screenSize = driver.manage().window().getSize();
int startx = screenSize.getWidth() / 2;
int endx = startx;
int starty = (int) (screenSize.getHeight() * 0.70);
int endy = (int) (screenSize.getHeight() * 0.20);
AndroidDriver androidDriver = (AndroidDriver) driver; // WebDriver to AndroidDriver
while(true) {
        // code to check with a text which is appears on the bottom of the page 
        //break;
        scroll(driver, startx, starty, endx, endy, 500);
        androidDriver.swipe(startX, startY, endX, endY, time);
}

这篇关于如何使用appium驱动程序从上到下滚动Android应用程序页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆