Hoppa till huvudinnehåll

getLocation

Bestäm ett elements position på sidan. Punkten (0, 0) avser det övre vänstra hörnet av sidan.

Usage
$(selector).getLocation(prop)
Parameters
NameTypeDetails
propstringkan vara "x" eller "y" för att få ett resultatvärde direkt för enklare kontroller
Example
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
});
Returns
  • <Object|Number> return: X- och Y-koordinaterna för elementet på sidan {x:number, y:number}

Welcome! How can I help?

WebdriverIO AI Copilot