How to use scroll/swipe in Python (except from coordinates)

Hey There people!

Is there any method, on which we can scroll to particular element in python without using coordinates.
I have used everything but all goes useless…

1 Like

Can you try this for iOS:

el = self.driver.find_element_by_id('locator_id')
self.driver.execute_script('mobile: scroll', {"element": el, "toVisible": True})

Hey @Venkatesh_Akula I have tried it. But its not.Its showing “Element not Found.”
Because element is not within view, we have to go down in order to click that element.

Oh, its working fine for me. Can you please let me know what page it is?

This is 1st image, which is from where I have to start scroll.

2nd pic is showing “Sign Out”, to which I want to scroll/swipe.
Now thats the case device is showing view of pic1, but I have to click “Sign Out”. which is exactly at bottom of the page.

Can you try scrolling to ‘Rate Our App’ using the code shared by me?

Nope, it didn’t worked @Venkatesh_Akula :frowning:

Refer to this issue thread which has specifically mentioned about python client as well.

I suggest all to start watching appium project in github, lots of learnings and interesting discussion happens there.

@VikramVI you need to look title of discussion again…
Whole topic is on coordinates and nothing. So your answer didn’t helped.

This is not working on Android, can some one please provide for Android.

Tried Below:

    self.desired_caps = {}
    self.desired_caps['platformName'] = 'Android'
    self.desired_caps['platformVersion'] = '8.0.0'
    self.desired_caps['deviceName'] = '23fbda3d'
    #self.desired_caps['deviceName'] = device_id
    self.desired_caps['fullReset'] = 'false'
    self.desired_caps['noReset'] = 'true'
    self.desired_caps['appPackage'] = 'com.whatsapp'
    self.desired_caps['appActivity'] = 'com.whatsapp.HomeActivity'
    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps)

Appium Version:V1.7.2


    self.driver.find_element_by_xpath("//android.widget.ImageView[@content-desc='More options']").click()
    element_to_tap = self.driver.find_element_by_xpath("//android.widget.TextView[@text='Fire']")
   self.driver.scroll(element_to_drag_to, element_to_tap)

Please help in this.

I have tried this as well.
This logic is also not working.

Can I Assume that there is no scrolling method in python for appium?

yes ,even i am also not able to scroll .Witing for the reply

Hi Taimoor,

Check this solution using “uiautomator”,This worked for me.

“new UiScrollable(new UiSelector()).scrollIntoView(element(”\value"));").click()

“new UiScrollable(new UiSelector()).scrollIntoView(text(“Ramu”));”).click()

Hey @ramu

I have tried this and pycharm is throwing me this exception.

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector (Locator Strategy ‘-android uiautomator’ is not supported for this session)

Guys there must be some way.

1 Like

Element1 = driver.find_element_by_xpath(‘Source Xpath’)
Element2 = driver.find_element_by_xpath(‘Destination Xpath’)

driver.scroll(Element1, Element2)

Did you get a solution?

Hi all
We can scroll untill the element is found
driver.find_elements_by_android_uiautomator(“new UiScrollable(new UiSelector().scrollable(true)”
+ “.instance(0)).scrollIntoView(new UiSelector().text(“Submit”).instance(0))”)
1.Try the above code for both in iOS and Android
2.In the place of >text(“Submit”).instance(0))")< Submit, enter the required text name.

driver.execute_script("mobile: scroll", {"direction": "down", element: element.getAttribute("id")})

You can try above code. details can be found on below link:

1 Like

Not wanting to supply coordinates , but instead supply a control, does not let you control stroke length surely?

grid = self.driver.find_element_by_accessibility_id(“ConnectionsGridView”)
coordinates = {“fromX”: grid.location[‘x’] + int(grid.size[‘width’]/2),
“fromY”: grid.location[‘y’] + grid.size[‘height’] - 5,
“toX”: grid.location[‘x’] + int(grid.size[‘width’] / 2),
“toY”: grid.location[‘y’] + 5
coordinates[“duration”] = 2
self.driver.execute_script(“mobile: dragFromToForDuration”,

Locates the view/control to scroll, and drags from within 5 pixels of bottom, to 5 pixels of the top. I call this code repeatedly to scroll until the element in the scroller is in view. It’s slow, but works reliably. Any slower than 2 seconds, and you get a “selection” instead, so I prefer 1 second drag.

@PraveenRKashyap Hi I tried your solution but getting this error:

E selenium.common.exceptions.InvalidSelectorException: Message: Could not parse expressionnew UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text(‘Sign Out’).instance(0)):UiScrollabledoesn't have suitable methodscrollIntoViewwith arguments [new UiSelector().text('Sign Out').instance(0)]: Could not parse expressionnew UiSelector().text(‘Sign Out’).instance(0):UiSelectordoesn't have suitable methodtextwith arguments ['Sign Out']: Could not parse expressionnew UiSelector().text(‘Sign Out’).instance(0): 'Sign Out' is not a string

here is the code:
self.driver.find_elements_by_android_uiautomator(“new UiScrollable(new UiSelector().scrollable(true)” + “.instance(0)).scrollIntoView(new UiSelector().text(‘Sign Out’).instance(0))”)