getLocation
Determine an element’s location on the page. The point (0, 0) refers to the upper-left corner of the page.
Usage
$(selector).getLocation(prop)
Parameters
Name | Type | Details |
---|---|---|
prop | String | can be "x" or "y" to get a result value directly for easier assertions |
Example
- Asynchronous Mode
- Synchronous Mode
getLocation.js
it('should demonstrate the getLocation function', async () => {
await browser.url('http://github.com');
const logo = await $('.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
});
getLocation.js
it('should demonstrate the getLocation function', () => {
browser.url('http://github.com');
const logo = $('.octicon-mark-github')
const location = logo.getLocation();
console.log(location); // outputs: { x: 150, y: 20 }
const xLocation = logo.getLocation('x')
console.log(xLocation); // outputs: 150
const yLocation = logo.getLocation('y')
console.log(yLocation); // outputs: 20
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.