获取尺寸
获取DOM元素的宽度和高度。
用法
$(selector).getSize(prop)
参数
名称 | 类型 | 详情 |
---|---|---|
prop 可选 | String | 要获取的尺寸 [可选] ("width" 或 "height") |
示例
getSize.js
it('should demonstrate the getSize command', async () => {
await browser.url('http://github.com')
const logo = await $('.octicon-mark-github')
const size = await logo.getSize()
console.log(size) // outputs: { width: 32, height: 32 }
const width = await logo.getSize('width')
console.log(width) // outputs: 32
const height = await logo.getSize('height')
console.log(height) // outputs: 32
})
返回值
- <Object|Number>
return
: 请求的元素尺寸 ({ width: <Number>, height: <Number> }
) 或者如果提供了prop参数,则返回实际的宽度/高度数值