check if div is visible code example

Example 1: jquery see if element is visible

.is(':visible')
//Selects all elements that are visible.

if($('#yourDiv').is(':visible')){
	//do stuff in here
}
//or
$('#yourDiv:visible').callYourFunction();

Example 2: check if element is visible

.is(':visible')
//Selects all elements that are visible.

if($('#Div').is(':visible')){
	// add whatever code you want to run here.
}

$('#yourDiv:visible').callYourFunction();

Example 3: javascript check if element is visible on screen

// Where el is the DOM element you'd like to test for visibility
<script>
  function isHidden(el) {
    return (el.offsetParent === null);
  }
  var el = document.getElementById('el');
  alert(isHidden(el));
</script>
// if true then element "el" is visible otherwise not visible

Example 4: how to scroll if element not visible

We can use javaScriptExecutor to scroll down
WebDriver driver = new ChromeDriver(); 
JavascriptExecutor jse =(JavascriptExecutor)driver
.jse.executeScript('window.scrollBy(0,250)', ’’);

Tags:

Misc Example