Aller au contenu principal

getLocation

Déterminer l'emplacement d'un élément sur la page. Le point (0, 0) fait référence au coin supérieur gauche de la page.

Utilisation
$(selector).getLocation(prop)
Paramètres
NomTypeDétails
propstringpeut être "x" ou "y" pour obtenir directement une valeur de résultat pour des assertions plus faciles
Exemple
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
});
Retourne
  • <Object|Number> return: Les coordonnées X et Y de l'élément sur la page {x:number, y:number}

Welcome! How can I help?

WebdriverIO AI Copilot