如何使用 appium 驱动程序从上到下滚动 android 应用程序页面? [英] How can I scroll an android app page from top to bottom using appium driver?
本文介绍了如何使用 appium 驱动程序从上到下滚动 android 应用程序页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从上到下滚动 Android 移动应用页面.
我尝试使用以下定义的编码进行滚动,并使用文本单击特定的 Web 元素.它工作正常.
<块引用>
//方法一driver.scrollTo(R");//方法二driver.ScrollToExact(Top");
- 但是我需要从上到下滚动整个文章页面,而不使用上面的 scroll() 方法.我已尝试使用以下编码,但我没有发生滚动动作.
<块引用>
//滚动到页面底部
((JavascriptExecutor) driver) .executeScript("window.scrollTo(0,document.body.scrollHeight)");
- 如何使用 appium 驱动程序从上到下滚动 Android 应用页面?
解决方案
在这里,您需要每次使用循环中的 text
进行检查,该循环出现在页面底部.如果找到的文本比打破循环.
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) 驱动程序;//WebDriver 到 AndroidDriver而(真){//检查出现在页面底部的文本的代码//休息;滚动(驱动程序,startx,starty,endx,endy,500);androidDriver.swipe(startX, startY, endX, endY, 时间);}
I want to scroll an android mobile app page from top to bottom.
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");
- But I need to scroll an full article page from top to bottom, without using above scroll() methods. I have tried with below coding, but scroll action doesn't happens for me.
// scroll to bottom of an page
((JavascriptExecutor) driver) .executeScript("window.scrollTo(0, document.body.scrollHeight)");
- How can I scroll an android app page from top to bottom using appium driver?
解决方案
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屋!
查看全文