javaselenium-webdriverappiumappium-android

Appium TouchAction class deprecated, tap on coordinates


Currently I have a webview within a react native app where I want to tap on an image that loads in the webview. Currently I am doing this with the touchAction class, but would like to use something different since it is deprecated.

seleniumSteps.driverWait("25000");
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(1280, 1013)).perform();

Solution

  • The TouchActions API was originally introduced as an alternative to the W3C Actions API, but it was not standardized and had limited support across different browsers and platforms.

    Therefore, to ensure better compatibility and standardization across different platforms, the W3C Actions API has been adopted as the standard API for performing user interactions in Selenium WebDriver.

    The API is based on a sequence of actions that are defined using a builder pattern.

    You can create W3CActions helper, declare constructor with AppiumDriver driver and implement method as

        public void tap(int x, int y) {
            PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
            Sequence tap = new Sequence(finger, 1);
            tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), x, y));
            tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
            tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
            driver.perform(Arrays.asList(tap));
        }
    

    In the code you actually create pointer, that emulates touch and then perform sequence of actions that represent moveToCoordinates, mouseDown, mouseUp actions.

    Reference 1

    Reference 2