View Source Improve this doc

getViewportSize

Get viewport size of the current browser window. This command only works on desktop browser or in a mobile environment with a webview enabled.

Usage

1
browser.getViewportSize(property);

Parameters

Param Type Details
property String if “width” or “height” is set it returns only that property

Example

getViewportSize.js
1
2
3
4
5
6
7
8
9
10
11
12
it('should return the viewport size', function () {
browser.url('http://webdriver.io');

var size = browser.getViewportSize()
console.log(size); // outputs: {width: 1024, height: 768}

var width = browser.getViewportSize('width')
console.log(size); // outputs: 1024

var height = browser.getViewportSize('height');
console.log(height); // outputs: 768
});

Returns

  • <Object>: viewport width and height of the browser

Uses