跳到主要内容

获取位置

确定元素在页面上的位置。点 (0, 0) 表示页面的左上角。

用法
$(selector).getLocation(prop)
参数
名称类型详情
propstring可以是 "x" 或 "y",直接获取结果值以便更容易地进行断言
示例
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
});
返回值
  • <Object|Number> return: 页面上元素的 X 和 Y 坐标 {x:number, y:number}

Welcome! How can I help?

WebdriverIO AI Copilot