Skip to main content

touchAction

Overview

warning

The touchAction command is deprecated. Please use action command instead:

await browser.action('pointer', {
parameters: { pointerType: 'touch' }
});

Use the touchAction command to perform gestures in mobile platform tests.

The command allows chaining ad hoc actions that will then be applied to the app element on the device.

The main actions you can use are:

  • press — requires an element or coordinates (x, y), or both
  • longPress — requires an element or coordinates (x, y), or both
  • tap — requires an element or coordinates (x, y), or both
  • moveTo — requires absolute coordinates (x, y)
  • wait — requires time in milliseconds
  • release — no parameters needed
warning

Currently, the touchAction command is only available for native apps and cannot be used for interacting with web applications.

Usage

await browser.$(selector).touchAction(action);

Command Parameters

NameTypeDescription
actionObjectThe action to perform.

Usage Examples

it("should do a touch gesture", async ({ browser }) => {
const screen = await browser.$("//UITextbox");

// simple touch action on an element
await screen.touchAction("tap");

// simple touch action with x and y coordinates
// touch coordinates are 30px to the right and 20px down from the element center
await screen.touchAction({
action: "tap",
x: 30,
y: 20,
});

// multi action on an element (drag&drop)
await screen.touchAction(["press", { action: "moveTo", x: 200, y: 300 }, "release"]);

// drag&drop to another element
const otherElement = await browser.$("//UIAApplication[1]/UIAElement[2]");
await screen.touchAction(["press", { action: "moveTo", element: otherElement }, "release"]);
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.