Determine an element's size in pixels.
For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to getLocation
and both return the dimensions and coordinates of the given element:
- x: X axis position of the top-left corner of the element, in CSS pixels
- y: Y axis position of the top-left corner of the element, in CSS pixels
- height: Height of the element’s bounding rectangle in CSS pixels;
- width: Width of the web element’s bounding rectangle in CSS pixels.
For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page.
Usage
browser.element(selector).getRect()
Example
export default {
demoTest(browser: NightwatchAPI): void {
const result = browser.element('#login').getRect();
console.log('result', result);
},
async demoTestAsync(browser: NightwatchAPI): Promise<void> {
const result = await browser.element('#login').getRect();
console.log('result', result);
}
}
Returns
Type | description |
---|---|
ScopedValue<*> |