Search code examples
pythonandroidselenium-webdriverappium

Simulate sliding on specific element (for app) without using pixels


I have an element in an app that's a sliding bar and would like to simulate it sliding. I'm wondering whether there's a method to simulate it by selecting an element, then sliding it a by percentage of the screen instead of amount of pixels swiped.

Current code used to simulate sliding:

    TouchAction(driver).tap(x=976, y=810).perform()
    TouchAction(driver).tap(x=102, y=810).perform()
    TouchAction(driver).tap(x=104, y=1259).perform()
    TouchAction(driver).tap(x=974, y=1257).perform()

What I don't like about it: Relies on touching instead of swiping, only works on devices of identical sizes.


Solution

  • You can use:

    TouchAction(driver).longPress(startingX, startingY).moveTo(endingX, endingY).release().perform();