getLocation
判斷元素在頁面上的位置。點 (0, 0) 指的是頁面的左上角。
用法
$(selector).getLocation(prop)
參數
名稱 | 類型 | 詳細資訊 |
---|---|---|
prop | 字串 | 可以是 "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
});