Reputation: 436
I am testing hybrid android app using Appium. I want to scroll to page bottom and then click on one link. Could anyone please tell me how to scroll to page bottom.
Many thanks!
Upvotes: 0
Views: 2829
Reputation: 3
scrollToExact
and scrollTo
method is depricated since JAVA client version 4.0.0 (https://github.com/appium/java-client/blob/master/README.md).
swipe
method also depricated (since 5.0.0-BETA1)
You can use UiScrollable
and UiSelector
and their methods to scroll any page (https://developer.android.com/reference/android/support/test/uiautomator/UiScrollable.html).
Example of code:
@AndroidFindBy (uiAutomator = "new UiScrollable(new
UiSelector()).scrollIntoView(new UiSelector().textContains(\"Question
\"))")
If you want scroll to the bottom of page, please create method that will do several steps (see code above) to find last element of page, otherwise you will get an error (Element not found).
I'm using this method:
@AndroidFindBy (uiAutomator = "new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().textContains(\"Element1\"))")
public WebElement scrollStepOne;
@AndroidFindBy (uiAutomator = "new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().textContains(\"Element2\"))")
public WebElement scrollStepTwo;
and then method:
public void scrollToTheBottom(){
scrollStepOne.isDisplayed();
scrollStepTwo.isDisplayed();
}
Hope it helps.
Upvotes: 0
Reputation: 1
Use
driver.ScrollTo("Text");
Text is the mark till where it need to scroll.
Upvotes: 0
Reputation: 107
This is how i tried a scroll down a side menu and find a logout
//Swipe down the side menu and click on logout
@Test
public void T4b_logout() throws InterruptedException{
size = driver.manage().window().getSize(); //Get the size of screen.
System.out.println(size);
int starty = (int) (size.height * 0.80);//Find starty point which is at bottom side of screen.
int endy = (int) (size.height * 0.20); //Find endy point which is at top side of screen.
int startx = size.width / 2; //Find horizontal point where you wants to swipe. It is in middle of screen width.
System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx); // int startx = size.width;
driver.swipe(startx, starty, startx, endy, 3000);//Swipe from Bottom to Top.
Thread.sleep(2000);
driver.findElement(By.name("Logout")).click();
driver.findElement(By.xpath("//android.widget.Button[@text='Ok']")).click();
}
Upvotes: 0
Reputation: 1370
First you can find the x and y coordinates by using inspector and then use this code:
driver.swipe(startx, starty, endx, endy, duration);
Upvotes: 1