I am writing automation app test case for iOS mobile app.
I am using appium version 1.4.8 , iOS simulator 6 and platform version 8.3.
I have seen a weird behavior, When I tried with scroll, it is working for sometime and sometime it doesn’t works for me. Now, completely scroll gesture doesn’t happening at all.
I have tried with below coding for scroll gesture. But, the scroll action doesn’t happens for me.
@amitjaincoer191, Ok Thanks for your reply. Can you explain, how can I correctly use touch action and swipe for scroll action. I really got confused, how can I proceed scroll gestures to click particular text or to go to down to the bottom of the page using swipe or touch action.
Watch coordinates carefully. Consider you are on app’s page of your phone. then below code will swipe screen left and right using TouchAction class
TouchAction tAction=new TouchAction(_driver);
int startx = _driver.findElement(By.name("Email")).getLocation().getX();
int starty = _driver.findElement(By.name("Email")).getLocation().getY();
int endx = _driver.findElement(By.name("Dev Settings")).getLocation().getX();
int endy = _driver.findElement(By.name("Dev Settings")).getLocation().getY();
System.out.println(startx + " ::::::: " + starty + " ::::::: " + endx + " ::::::: " + endy);
//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(1000);
//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();
From what I understand, you can’t. I could be wrong, but I’ve tried about 20 different solutions posted here and elsewhere and nothing has worked for me.
Xcode 7 (and El Capitan) are likely out next month and contains a wholly revamped testing system. When that comes around you should be able to do just about any gesture you want. Hopefully.
Actually It worked for me on Android app.
But I feel from code point of view it is independent of platform.
Note : You need to make sure that are we are preforming swipe or scroll should be scrollable
Can you share your error what you are getting and also on which app you have tried ??
scrolling and swiping is just a matter of getting correct from and to coordinates and it will work provided area is scrollable
@amitjaincoer191, I have tried your code for scroll action. I don’t get any error and all, but the scroll action doesn’t happens for me. I want to scroll an page from top to bottom. I need some clarification with above code. How can I take endx and endy web element?
@amitjaincoer191, I have tried the above code for swiping a photo gallery image. But, the swipe action doesn’t happens for me. I have tried this code for iOS app in iOS simulator 8.3 platform version. I have pasted the appium locator details for that particular image. I need to swipe from right to left and vice versa. How can I use the below information to take the web element to obtain startx, starty ,endx and endy.
So if I say we have a app Page with an element on top of page and one on bottom of page
elememt.top of page.getX - startX
element.top of page.getY - start Y
element.bottom of page.getX - end X
element.bottom of page.getY - end Y
so depending on coordinates passed swipe or scroll will happen
driver.swipe(0,0,300,0) - this will scroll horizontally right
driver.swipe(300,0,100,0) - this will scroll horizontally left
driver.swipe(0,0,0,300) - this will scroll vertically down
driver.swipe(100,500,100,100) - this will scroll vertically up
same way touchactions also work.
I have seen u r other question also so if you want to use loop to scroll to bottom then u can use loop but u must have a terminating condition for loop …
I have example from android app context in case u r interested I can post it.
I worked less on iOS app but what ever worked I found that absolute xpath returned by inspector very less reliable. so depend on other strategy like classname,relative xpath etc
you means this is a page where u can see thumbnail of images and u want to scroll it.
You can try like this
driver.findElement(By.xpath("//UIImage[1]")) - get its x an y coordinate for start
driver.findElement(By.xpath("//UIImage[5]")) - get its x an y coordinate for end
pass to swipe method
Try like this
// Make sure right view should be present when this code is executed
// perform horizontal swipe from right to left so that next image will appear
int x = driver.manage().window().getSize().getHeight();
int y = driver.manage().window().getSize().getWidth();
driver.swipe(x/3+300, y/2-150, x/3, y/2-150, 2000);
I have tried with above code. It throws below error message.
Error Message:-
org.openqa.selenium.WebDriverException: An error occurred while executing user supplied JavaScript. (WARNING: The server did not provide any stacktrace information)
It throws error in below line //driver.swipe(x/3+300, y/2-150, x/3, y/2-150, 2000);
@amitjaincoer191, Thanks for your information, I have really got struck with scroll and swipe gestures more than a week. I have tried so many solution for gestures, still its not working. I will upgrade java client version and give a try with above code.
scrollTo() and scrollToExact() methods work on UIATableView elements which contains UIATableCell elements.
What you need to do is, first find a UIATableView element using
WebElement tableView = driver.findElement(MobileBy.xpath("//UIATableView[3]"))
then do
tableView.scrollTo(“DesiredText”) - and this will take you that element and return you WebElement having text on which you intend to scroll.