Reputation: 149
I tried scrollTo() to scroll my app page using andriod driver, but not worked because it is deprecated from javaclient 4.1.2.
I have gone through below link but couldn't find any solution . How can I scroll an android app page from top to bottom using appium driver?
Please provide me solution
Upvotes: 3
Views: 5394
Reputation: 626
We can use the following the code snippet to scroll down but please make sure you catch the exceptions.
try {
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"\"))");
}catch(Exception e) {
System.out.println("whatever");
}
Upvotes: 0
Reputation: 1387
@Test
public void testScroll()throws Exception
{
for(int i=0;i<4;i++)
{
Thread.sleep(2000);
if (driver.findElement(By.name("end_item")).isDisplayed())
{
driver.findElement(By.name("end_item")).click();
break;
}
else
{
verticalScroll();
}
}
}
public void verticalScroll()
{
size=driver.manage().window().getSize();
int y_start=(int)(size.height*0.60);
int y_end=(int)(size.height*0.30);
int x=size.width/2;
driver.swipe(x,y_start,x,y_end,4000);
}
The above example works with vertical scroll and it is based on the example given at this blog for horizontal scroll http://qaautomated.blogspot.in/2016/02/how-to-do-horizontal-scroll-in-appium.html I hope this works for you.
Upvotes: 0
Reputation: 454
you can try this below code, i was trying this code on settings page..
AppiumDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap1);
driver.scrollTo("About phone");
Pass the String which is present in the bottom of your app page.
driver.scrollTo("Enter your value");
Use appropriate wait Statements.
Upvotes: 0
Reputation: 976
User swipe method as below:
driver.swipe(startx, starty, endx, endy, duration);
e.g. for swipe down
driver.swipe(100, 100, 100, 900, 3000);
According you can change the x and y co-ordinates.
Upvotes: 0
Reputation: 2140
My example is from python but it will work for Java as well just use java syntax to find element like
driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("**/Put some text which is at bottom of screen to scroll screen/**").instance(0))')
for more details you can go-through the https://developer.android.com/reference/android/support/test/uiautomator/UiScrollable.html and https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html
Upvotes: 2