Check if Scroll Bar is available in Page Selenium WebDriver - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Friday 30 March 2018

Check if Scroll Bar is available in Page Selenium WebDriver

package test;


import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

public class my {

static WebDriver driver =new FirefoxDriver();
public static void GoogleSearch() throws Exception {
driver.get("http://www.google.co.in");
driver.manage().window().maximize();
String execScript = "return document.documentElement.scrollHeight>document.documentElement.clientHeight;";
JavascriptExecutor scrollBarPresent = (JavascriptExecutor) driver;
Boolean test = (Boolean) (scrollBarPresent.executeScript(execScript));
if (test == true) {
System.out.print("Scrollbar is present.");
} else if (test == false){
System.out.print("Scrollbar is not present.");
}
}

public static void main(String[] args) {
try {
GoogleSearch();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}



Explanation

I will make it easier:

scrollHeight

clientHeight + non-visible height
Height of all content + paddings, despite of element height:
scrollHeight

clientHeight

visible height of content + visible padding
Visible height: content portion limited by explicitly defined element height

offsetHeight

clientHeight + border + scrollbar
Height occupied by the element on document.
enter image description here

No comments:

Post a Comment