【问题标题】:Issue with scroll down in android Appium WebDriverandroid Appium WebDriver中向下滚动的问题
【发布时间】:2015-01-23 02:31:34
【问题描述】:
如何向下滚动查看 Appium WebDriver 中的元素外观?我们正在使用模拟器进行自动化。
任何建议/帮助将不胜感激。
【问题讨论】:
标签:
java
webdriver
emulation
appium
【解决方案1】:
这应该可以正常工作:
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Put the text you want to scroll to here\"));");
如果你想在滚动到元素后点击它,添加一个click()方法:
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Put the text you want to scroll to here\"));").click();
【解决方案2】:
尝试使用下面的代码滚动到底部:-
Dimension size= driver.manage().window().getSize();
int starty=(int)(size.height*0.80);
int endy=(int)(size.height*0.20);
int startx=size.width/2;
driver.swipe(startx, starty, startx, endy, 3000);
【解决方案3】:
由于最新版本的 appium(1.6.3) 现在不推荐使用 scrollTo() 和更多相关方法。您可以尝试以下代码行。它对我有用,希望它也对你有用......你可以根据你的要求改变尺寸。
Dimension dimensions = driver.manage().window().getSize();
//System.out.println("Dimension value = "+dimensions);
Double screenHeightStart = dimensions.getHeight() * 0.5;
//System.out.println("Screen Height start Value="+screenHeightStart);
int scrollStart = screenHeightStart.intValue();
//System.out.println("Scroll Start Value="+scrollStart);
Double screenHeightEnd = dimensions.getHeight() * 0.2;
// System.out.println("Screen Height start End="+screenHeightEnd);
int scrollEnd = screenHeightEnd.intValue();
//System.out.println("Scroll end Value="+scrollEnd);
driver.swipe(0,scrollStart,0,scrollEnd,2000);
sleep(3000);
【解决方案4】:
这行得通
TouchAction action = new TouchAction(androidDriver);
action.press(0, 500)
.waitAction(200)
.moveTo(0, 200)
.release()
.perform();
只需使用坐标即可获得所需的滑动。
【解决方案5】:
为此,您可以使用 AppiumDriver
的
scrollToExact() 或
scrollTo() 函数
AppiumDriver driver = new AppiumDriver();
当字符串包含“abc”时滚动
driver.scrollTo("abc");
或者对于确切的字符串“abc”,你可以使用
driver.scrollToExact("abc");