# Can't get setMaxSearchSwipes() to work with driver.findElement(MobileBy.AndroidUIAutomator)

**URL:** <https://discuss.appium.io/t/cant-get-setmaxsearchswipes-to-work-with-driver-findelement-mobileby-androiduiautomator/29935>\
**Category:** Support\
**Created:** [March 11, 2020, 8:41pm UTC](https://discuss.appium.io/t/cant-get-setmaxsearchswipes-to-work-with-driver-findelement-mobileby-androiduiautomator/29935 "2020-03-11T20:41:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Vogel](https://discuss.appium.io/user_avatar/discuss.appium.io/mike_vogel/32/7223_2.png) [@Mike\_Vogel](https://discuss.appium.io/u/Mike_Vogel)\
**Post date:** [March 11, 2020, 8:41pm UTC](https://discuss.appium.io/t/cant-get-setmaxsearchswipes-to-work-with-driver-findelement-mobileby-androiduiautomator/29935/1 "2020-03-11T20:41:27Z")

</div>

I am trying to find certain cards or tiles in an Android Recycler view, using the below code I can get it to work sometimes.

```
    MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiScrollable(new UiSelector().resourceId(\"" + resourceID + "\")).getChildByText("
                    + "new UiSelector().className(\"" + className + "\"),\"" + buttonText +"\")"));

```

The issue is, about half the time it will quit looking before finding the desired text, so I’ve been trying to use the above code with setMaxSearchSwipes(20)

I’ve tried the following, but the code seems to only try swiping 5 times before it quits.

```
    MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiScrollable(new UiSelector().resourceId(\"" + resourceID + "\")).setMaxSearchSwipes(20).getChildByText("
                    + "new UiSelector().className(\"" + className + "\"),\"" + buttonText +"\")"));

```

and

```
    MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiScrollable(new UiSelector().resourceId(\"" + resourceID + "\")).getChildByText("
                    + "new UiSelector().className(\"" + className + "\"),\"" + buttonText +"\").setMaxSearchSwipes(20)"));
```

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [March 11, 2020, 10:22pm UTC](https://discuss.appium.io/t/cant-get-setmaxsearchswipes-to-work-with-driver-findelement-mobileby-androiduiautomator/29935/2 "2020-03-11T22:22:01Z")

</div>

> [@Mike\_Vogel](#):
>
> getChildByText

why you do not use " scrollIntoView" ?

---

<div class="post-metadata">

**Author:** ![Mike\_Vogel](https://discuss.appium.io/user_avatar/discuss.appium.io/mike_vogel/32/7223_2.png) [@Mike\_Vogel](https://discuss.appium.io/u/Mike_Vogel)\
**Post date:** [March 12, 2020, 3:07pm UTC](https://discuss.appium.io/t/cant-get-setmaxsearchswipes-to-work-with-driver-findelement-mobileby-androiduiautomator/29935/3 "2020-03-12T15:07:29Z")

</div>

Hey Aleksei,

Thank you for the response! I’ve tried a bit of everything I’ve found on different support articles, I had tried the scrollIntoView previously and couldn’t get it to work, but I think I was doing it wrong.

I tried the following with scrollIntoView and it is working much more consistently:  
MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(  
“new UiScrollable(new UiSelector().resourceIdMatches(”" + resourceID + “”)).setMaxSearchSwipes(15).scrollIntoView("  
+ “new UiSelector().text(”" + buttonText + “”))"));

Thanks a bunch!

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [March 12, 2020, 5:43pm UTC](https://discuss.appium.io/t/cant-get-setmaxsearchswipes-to-work-with-driver-findelement-mobileby-androiduiautomator/29935/4 "2020-03-12T17:43:03Z")

</div>

try -\> [Find element with certain text inside another element using UISelector query](https://discuss.appium.io/t/find-element-with-certain-text-inside-another-element-using-uiselector-query/29845/8)

magic in “.scrollable(true)” plus you can add “setMaxSearchSwipes” PLUS add direction if it e.g. horizontal.
