[英]Issue with scroll down in android Appium WebDriver
如何向下滚动 Appium WebDriver 中的元素外观? 我们正在使用模拟器进行自动化。
任何建议/帮助将不胜感激。
这有效
TouchAction action = new TouchAction(androidDriver);
action.press(0, 500)
.waitAction(200)
.moveTo(0, 200)
.release()
.perform();
只需使用坐标即可获得所需的滑动效果。
为此,您可以使用AppiumDriver 的scrollToExact()
或scrollTo()
函数
AppiumDriver driver = new AppiumDriver();
当字符串包含“abc”时滚动
driver.scrollTo("abc");
或者对于出现的确切字符串“abc”,您可以使用
driver.scrollToExact("abc");
您可以使用
driver.scrollTo(value);
或者
driver.swipe(start.x, start.y, end.x, end.y, duration)
供参考: http : //appium.io/slate/en/0.18.x/?ruby#automating-mobile-gestures
由于最新版本的 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);
尝试使用以下代码滚动到底部:-
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);
这应该可以正常工作:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.