问题
How can I scroll down for the element appearance in Appium WebDriver? We are using an emulator for automation.
Any suggestions/help would be appreciated.
回答1:
This works
TouchAction action = new TouchAction(androidDriver);
action.press(0, 500)
.waitAction(200)
.moveTo(0, 200)
.release()
.perform();
Just play with the coordinates to get the desidered swiping.
回答2:
For that you can use scrollToExact()
or scrollTo()
functions of the AppiumDriver
AppiumDriver driver = new AppiumDriver();
to scroll when string contains "abc"
driver.scrollTo("abc");
or for exact string "abc" appear you can use
driver.scrollToExact("abc");
回答3:
You can use
driver.scrollTo(value);
or
driver.swipe(start.x, start.y, end.x, end.y, duration)
For reference : http://appium.io/slate/en/0.18.x/?ruby#automating-mobile-gestures
回答4:
Since scrollTo() and many more related methods are deprecated now with the latest version of appium(1.6.3). You can try the below line of code. It worked for me, hope it works for you as well......you can change the dimension as per your requirements.
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);
回答5:
Try using the below code to scroll till bottom: -
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);
来源:https://stackoverflow.com/questions/27120762/issue-with-scroll-down-in-android-appium-webdriver