I think better to develop an algorithm. pseudo could be like this:
Take the list of visible elements
take position of first visible element
take position of last visible element
swipe from last visible element to first visible element
continue swiping until the list of all visible elements is not same
In simple words, consider you have a list of options inside the menu page - A, B, C, D & E while E is at the end and you have to scroll up to view it. Assume with a real device in hand you will manually try to scroll up, so you will put finger in point 2 and scroll it till point 1 (down to up finger movement). Iâm doing the same in my code.
A
B
C
D
E
element_to_tap = D
element_to_drag_to = B
and say Appium to scroll up from D to B, so my screen will move up and I will be shown the options in the bottom. Hope this helps you understand it better.
May you help me please? explain me what is with that âself.driverâ. I try to learn how to use java and Appium and my Eclipse does not recognize that âselfâ. Can you give me an concrete example how to use scroll, I need that method so much⌠please help me
Hi @mota,
I am also facing the same issue.how did you solve this issue.could you please post me the piece of code here?
I tried this
driver.scrollToExact(âTextâ);
and
public void scrollDown() {
Dimension size = driver.manage().window().getSize();
int x = size.width / 2;
int starty = (int) (size.height * 0.60);
int endy = (int) (size.height * 0.10);
driver.swipe(x, starty, x, starty, 2000);
}
also I tried @sujata_kalluri solution too.But this gives me exception.
Please help me out if you got the solution.
I have a screen with dynamic elements and i would like to click on each one of them. So i have created the following code. The scroll goes up and down and it clicks on most of the elements, however it doesnât click on all of them (when test finishes all is successful and no error messages). Any work around this? thank you in advance
@When("^I click on the available excursions$")
public void i_click_on_the_available_excursions() throws Throwable {
wait.until(ExpectedConditions.visibilityOf(destinationDetailsScreen.Back_Btn));
driver.scrollTo(âdestinationCTAâ);
hello,
i am using Appium v1.6.3 and java client 4.1.2. i am able to scroll on page top to bottom. scrollTo function is not supported .please help and share the code snippet how to scroll down and click on element.
i used touchaction class but itâs not working.
TouchAction action = new TouchAction(driver);
// action.longPress(540,1725).moveTo(577,497).release().perform();
You can create a webelement and get location of that element and use it in
swipe commandâ. You can refer below code for getting coordinates location:â
WebâElement element = driver.findElementâBy().getLocation();
int e1 = element.getX();
Hello Mitesh,
i am using this code but itâs not working.Please write code for me. i am not able to scroll till end of page and also not able to click on element.
public void swipe_vertical(){
Dimension size = driver.manage().window().getSize();
//int height = size.height;
//int width = size.width;
System.out.println("height=" +size.height+"width="+size.width);
int startx = size.width/2;
int endx = size.width/2;
int starty = size.height - size.height/4;
int endy = size.height/4;
System.out.println("vertical swipe");
WebElement element = driver.findElementByAndroidUIAutomator("Uiselector().className(\"android.widget.LinearLayout[[5]\").text(\"Snapdeal\")");
do{
driver.swipe(startx, starty, endx, endy, 600);
}while(!element.isDisplayed());
//WebElement element is the one till you want to scroll
public void swipeTo(WebElement element) {
int startx = 0, starty = 0, endx = 0, endy = 0;
Dimension size = driver.manage().window().getSize();
try {
TouchAction tAction = new TouchAction(driver);
startx = (int) (size.width * 0.5);
endx = (int) (size.width * 0.5);
starty = (int) (size.height * 0.6);
endy = (int) (size.height * 0.4);
while (!element.isDisplayed()) {
//First tap on the screen and swipe it right using moveTo function
tAction.press(startx + 20, starty + 20).moveTo(endx + 20, endy + 20).release().perform();
Thread.sleep(400);
//Second tap on the screen and swipe it left using moveTo function
tAction.press(endx + 20, endy + 20).moveTo(startx + 20, starty + 20).release().perform();
Thread.sleep(400);
}
} catch (Exception e) {
e.printStackTrace();
}
Probably you are missing to give the click event. Please try this below code:
try{
while(!driver.findElement.isDisplayed()){
driver.swipe(startx, starty, endx, endy, 200);
}
}catch(Exception e){
driver.swipe(startx, starty, endx, endy, 200);
}