Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

java - On Android Mobile application using appium , how to fetch the list of web-Elements for which we need to scroll?

Suppose I have total Six "remove" button on my page. Three are visible and for other Three I need to scroll . When I am trying to find the total count , it is showing me the count as 3 which is visible on the screen only. How to get the total count ? Is there any work around for that ? Scrolling by androidUI automator logic wont work because at any point of time only 3 "Remove" buttons can be fit to the Screen.

question from:https://stackoverflow.com/questions/65840722/on-android-mobile-application-using-appium-how-to-fetch-the-list-of-web-elemen

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As per your example, Follow these steps:

  • Get the list of elements for first three buttons, store the count in some variable:

List<WebElement> list = (List<WebElement>) driver.findElements(By.xpath("your xpath"));

(you can use your locator strategy as per requirement)

  • Perform scroll
public static void scrollDown() {
        int pressX = driver.manage().window().getSize().width / 2;
        int bottomY = driver.manage().window().getSize().height * 4/5;
        int topY = driver.manage().window().getSize().height / 8;
        scroll(pressX, bottomY, pressX, topY);
    }

public static void scroll(int fromX, int fromY, int toX, int toY) {
        TouchAction touchAction = new TouchAction(mobileDriver);
        touchAction.longPress(PointOption.point(fromX, fromY)).moveTo(PointOption.point(toX, toY)).release().perform();
    }

  • Again get the list of elements for the last three buttons, store the count in some variable.

List<WebElement> list2 = (List<WebElement>) driver.findElements(By.xpath("your xpath"));

  • Calculate the count

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...