View Source Improve this doc

isVisibleWithinViewport

Return true if the selected DOM-element found by given selector is visible and within the viewport.

Usage

1
browser.isVisibleWithinViewport(selector);

Parameters

Param Type Details
selector String DOM-element

Example

index.html
1
2
3
4
<div id="notDisplayed" style="display: none"></div>
<div id="notVisible" style="visibility: hidden"></div>
<div id="notInViewport" style="position:absolute; left: 9999999"></div>
<div id="zeroOpacity" style="opacity: 0"></div>
isVisible.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
it('should detect if an element is visible', function () {
var isVisibleWithinViewport = browser.isVisibleWithinViewport('#notDisplayed');
console.log(isVisibleWithinViewport); // outputs: false

isVisibleWithinViewport = browser.isVisibleWithinViewport('#notVisible');
console.log(isVisibleWithinViewport); // outputs: false

isVisibleWithinViewport = browser.isVisibleWithinViewport('#notExisting');
console.log(isVisibleWithinViewport); // outputs: false

isVisibleWithinViewport = browser.isVisibleWithinViewport('#notInViewport');
console.log(isVisibleWithinViewport); // outputs: false

isVisibleWithinViewport = browser.isVisibleWithinViewport('#zeroOpacity');
console.log(isVisibleWithinViewport); // outputs: false
});

Returns

  • <Boolean/Boolean[]>: true if element(s)* [is|are] visible

Uses