Reputation: 11
how to handle identify scrollbar is disabled or not present
I tried to find the xpath for scrollbar to check if it is there. But as there were not more elements in frame so scrollbar was disabled or not available.
Upvotes: 0
Views: 48
Reputation: 1583
you can run following code:
JavascriptExecutor jsExec = (JavascriptExecutor) driver;
Boolean isScroll = (Boolean) (jsExec.executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight;"));
Important part is JavaScript code that check height of browser.
Full code:
WebDriver driver = new ChromeDriver();
driver.get("https://selenium.dev");
JavascriptExecutor jsExec = (JavascriptExecutor) driver;
Boolean isScroll = (Boolean) (jsExec
.executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight;"));
if (isScroll == true) {
System.out.print("Scrollbar is exist.");
} else if (isScroll == false) {
System.out.print("Scrollbar is not exist.");
}
driver.quit();
Upvotes: 1