Appium giving null response when trying to find it inside a scroll view using xpath

463 views Asked by At

I am currently new to appium. I am trying to click on an item inside the scroll view of my app in which the element is found by xpath.

MobileElement el11 = (MobileElement) driver.findElementByXPath(
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[4]/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[7]/android.view.ViewGroup[2]/android.widget.TextView");
        System.out.println(el11.getText().equalsIgnoreCase("View More"));
        el11.click();
        System.out.println("Tap performed");

Inside the 1st syso statement im getting true. and the seocnd syso statement im getting tap performed.

But inside the appium server log. click() function is returning null. When i tried to tap the item inside the appium inspector the tap results into a navigation of another page.

Please help

1

There are 1 answers

0
dmle On

To click any element inside scrollable view, it is good to use UIAutomator selector, first to find it and scroll it into viewport visible area, after that you can make a click.

MobileElement el11 = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
        "new UiScrollable(new UiSelector().scrollable(true).instance(0))" +
         ".scrollIntoView(new UiSelector().text(\"View More\"))"));
el11.click();

As a side note, searching by text is a bad approach since you might have it in different labels. Try to use resource-id whenever it is possible