getElementSize

Get the width and height for an DOM-element based given selector.

Usage

1
browser.getElementSize(selector,prop);

Parameters

Param Type Details
selector String element with requested size
prop String* size to receive [optional] (“width” or “height”)

Example

getElementSize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
it('should give me the size of an element', function () {
browser.url('http://github.com')
var logo = $('.octicon-mark-github')

var size = logo.getElementSize()
// or
size = browser.getElementSize('.octicon-mark-github')
console.log(size) // outputs: { width: 32, height: 32 }

var width = logo.getElementSize('width')
// or
width = browser.getElementSize('.octicon-mark-github', 'width')
console.log(width) // outputs: 32

var height = logo.getElementSize('height')
// or
height = browser.getElementSize('.octicon-mark-github', 'height')
console.log(height) // outputs: 32
})

Returns

  • <Object/Number>: requested element size ({ width: <Number>, height: <Number> }) or actual width/height as number if prop param is given

Uses