Skip to main content

getSize

Overview

Use the getSize command to get the width and height of a DOM element.

Usage

await browser.$(selector).getSize(prop);

Command Parameters

NameTypeDescription
propStringOptional parameter. The size to retrieve: "width" or "height". If not specified, the command will return an object of the form { width, height }.

Usage Examples

it("should demonstrate the getSize command", async ({ browser }) => {
await browser.url("http://github.com");
const logo = await browser.$(".octicon-mark-github");

const size = await logo.getSize();
console.log(size); // outputs: { width: 32, height: 32 }

const width = await logo.getSize("width");
console.log(width); // outputs: 32

const height = await logo.getSize("height");
console.log(height); // outputs: 32
});

References

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