getLocation
Overview
Use the getLocation
command to determine the location of an element on the page.
The point (0, 0)
refers to the top left corner of the page.
Usage
await browser.$(selector).getLocation(prop);
Command Parameters
Name | Type | Description |
prop | String | Optional parameter. Can be "x" or "y" to directly get the desired value for simpler checks. If not specified, the command returns an object of the form { x, y }. |
Usage Examples
it("should demonstrate the getLocation function", async ({ browser }) => {
await browser.url("http://github.com");
const logo = await browser.$(".octicon-mark-github");
const location = await logo.getLocation();
console.log(location); // outputs: { x: 150, y: 20 }
const xLocation = await logo.getLocation("x");
console.log(xLocation); // outputs: 150
const yLocation = await logo.getLocation("y");
console.log(yLocation); // outputs: 20
});
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.