Reputation: 1477
I want to scroll an android mobile app page from top to bottom.
I have tried with below defined coding for scroll and click for specific web element using text. It works fine.
// method 1 driver.scrollTo("R"); // method 2 driver.ScrollToExact("Top");
// scroll to bottom of an page
((JavascriptExecutor) driver) .executeScript("window.scrollTo(0, document.body.scrollHeight)");
Upvotes: 2
Views: 3741
Reputation: 128
Step 1
public boolean isElementFound(String zoneName, String text, int index) {
try{
//text=text.concat("["+index+"]");
//System.out.println(text);
WebElement webElement = appiumDriver.findElement(By.xpath(text));
System.out.println("isElementFound : true :"+text + "true");
//ReportAppium.getSnapShot(appiumDriver);
}catch(NoSuchElementException e){
System.out.println("isElementFound : false :"+text);
//ReportAppium.getSnapShot(appiumDriver, "isElementFound- "+text + "false");
return false;
}
return true;
}
Step 2
while(isElementFound(element)==false)
{
public void swipe(int startx, int starty, int endx,int endy,int duration)
{
TouchAction touchAction = new TouchAction(appiumDriver);
System.out.println(startx+" "+starty);
System.out.println("Entering swipe");
System.out.println("Swipe from "+startx +" " +starty +"to" +endx +" " +endy );
touchAction.press(startx, starty).waitAction(duration).moveTo(endx,endy).release().perform();
}
}
Upvotes: 0
Reputation: 393
Here you need to check everytime with a text
in the loop, that appears on the bottom of the page. If the text found than break the loop.
Dimension screenSize = driver.manage().window().getSize();
int startx = screenSize.getWidth() / 2;
int endx = startx;
int starty = (int) (screenSize.getHeight() * 0.70);
int endy = (int) (screenSize.getHeight() * 0.20);
AndroidDriver androidDriver = (AndroidDriver) driver; // WebDriver to AndroidDriver
while(true) {
// code to check with a text which is appears on the bottom of the page
//break;
scroll(driver, startx, starty, endx, endy, 500);
androidDriver.swipe(startX, startY, endX, endY, time);
}
Upvotes: 1
Reputation: 1
Use
driver.scrollTo("Text");
Note: Text content you can find from node detail screen of UI Automator Viewer Tool
Upvotes: -1
Reputation: 933
Use :
driver.scrollTo("text");
Where text is the name of the button(You can check the text in UIAutomatorviewer)
Upvotes: 0