How to swipe in a specific area until target element is show?

appium version: V1.13.0
simulator android version: 9.0
i want to swipe in the specific area like below picture shows, and until the “edit” element is appear.
the target element is not in the current page, here is my codes, but swipe action doesn’t work.
touchAction is useless,too. cause element touch press is beyond this area.
1 2

area = self.driver.find_element_by_class_name("android.support.v7.widget.RecyclerView").size
height = area["height"]
width = area["width"]
while True:
    try:
        matchString = "Edit"
        end_el = self.driver.find_element_by_android_uiautomator("new UiSelector().\
       text(\""+matchString+"\")").is_displayed()
        if end_el:
            break
    except:
        self.driver.swipe_right(width/2, height/2, width/3, height/2, 200)
        #TouchAction(self.driver).press(x=width/4, y=height/2). \
        #                    move_to(x=width/2, y=height/2).release().perform()
        continue

many thanks for help!

@johny try:

String text = "your text"
WebElement el = driver.findElement(MobileBy
                    .AndroidUIAutomator("new UiScrollable(new UiSelector()).setAsVerticalList().scrollIntoView("
                            + "new UiSelector().text(\""+text+"\"));"))); 

as far as you have several scroll views also better set scrollView ID:

String text = "your text"
WebElement el = driver.findElement(MobileBy
                    .AndroidUIAutomator("new UiScrollable(new UiSelector().resourceId(\"YOUR_RECYCLERVIEW_ID\")).setAsVerticalList().scrollIntoView("
                            + "new UiSelector().text(\""+text+"\"));"))); 
2 Likes

@Aleksei thanks for reply first, i’ve tried your code, but it doesn’t work.cause it’s scroll the page vertically, all i want is swipe in that area horizontally

Oiiiii replace to horisontal :slight_smile:

setAsHorizontalList

@Aleksei i don’t want to swipe the whole page :joy: i mean i need swipe in a specific area to find an element not in current page.

It will swipe whatever you asking it for! If on page several scroll views it will swipe whatever first which means random. So you need specify in such case scrollView element that needed to be swiped.

So in general you can specify view id, orientation (horisontal or vertical) and swipe direction. These all needed when view has several scrollViews - to help uiAutomator understand what is needed.

On your view you have at least 3 scrollViews.

@Aleksei Thank you so much, it’s ok now, like you said before(method 2), i have to specify which element i need to swipe, use attribute like resource-id or className etc.

Hi @Aleksei I tried using the same command its swiping but instead of swiping down its swiping up . Is there is any way to say the direction in which it will swipe .

Code snippet:

MobileElement element = (MobileElement)getTLDriver().findElement(MobileBy.AndroidUIAutomator(
                    "new UiScrollable(new UiSelector().resourceId(\"resourceId\")).setAsVerticalList().scrollIntoView("
                            + "new UiSelector().text(\"Paragraph\"))"));

@deepikathiru all command are here -> https://developer.android.com/reference/android/support/test/uiautomator/UiScrollable

UISelector tries first to find start of scrollableView.

Thanks @Aleksei I have a doubt, the ListView I am trying to scroll has its scrollable value as ‘false’ does that got any impact with scrolling that Appium is trying to do ?

no idea. but if you try to check “scrollable=true” - it will affect. just not add it.

Ohkk will ask them to try and let me check on that