0

I am trying to automate a native android app using Appium. I am using the java client for the same. Below are the dependencies that I have included. Since I am using version 7 of the java client, there's no support for scroll and swipe method. SO alternatively how do I scroll to a particular element?? I have come across some code snippets using TouchAction class, but I just want to know if there's any alternative solution apart from the TouchAction class?? Maven dependency -

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>

3 Answers 3

2

You can use findElementByAndroidUIAutomator with different conditions like text,description:

((AndroidDriver<?>) appiumDriver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+ text + "\").instance(0))");
Sign up to request clarification or add additional context in comments.

Comments

0
public MobileElement scrollElementByTextUsingDescription(String scrollableListContDesc, String uiClassSelector, String text) {
        return driver.findElement(MobileBy.AndroidUIAutomator(
           "new UiScrollable(new UiSelector().description(\"" + scrollableList + "\"))" +
           ".getChildByText(new UiSelector().className(\"" + uiClassSelector + "\"), \"" + text + "\")"));
    }

scrollableListContDesc is automationId/cont-Description of scrollable list

uiClassSelector is the class name of scrollable list e.g android.view.View

text is the text of the element upto where you want to scroll.

If you don't have cont-description in scrollable list, you can use following method:

public MobileElement scrollElementByTextUsingId(String scrollableListId, String uiClassSelector, String text) {
            return driver.findElement(MobileBy.AndroidUIAutomator(
               "new UiScrollable(new UiSelector().resourceId(\"" + scrollableListId + "\"))" +
               ".getChildByText(new UiSelector().className(\"" + uiClassSelector + "\"), \"" + text + "\")"));
        }

scrollableListId is id/resourceId of scrollable list

Comments

-1

UIScrollable/UISelector is one alternative to TouchActions that you can use to scroll/swipe. Example:

MobileElement element = driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiScrollable(new UiSelector().resourceId(\"com.android.vending:id/data_view\")).scrollIntoView("
            + "new UiSelector().textContains(\"HelloWorld\").instance(2))"));

This blog post covers a variety of solutions to swipe/scroll well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.