user3356141
user3356141

Reputation: 501

Asserting the presence of scrollbar using Selenium (webdriver java cucumber)

I have a responsive website I need to test. If the website goes to the window size of a Tablet, I want the test to check if there is a horizontal scrollbar. According to the design they can never be present on a tablet.

Does anyone have a piece of pseudo-code to assert the presence of a horizontal scrollbar using Selenium Webdriver Java Cucumber?

Upvotes: 7

Views: 6754

Answers (1)

Richard
Richard

Reputation: 9029

You can test this with javascriptExecutor:

Vertical scrollbar:

boolean scrollBarPresent = ((JavascriptExecutor)driver).executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight;");

Horizontal scrollbar:

boolean scrollBarPresent = ((JavascriptExecutor)driver).executeScript("return document.documentElement.scrollWidth>document.documentElement.clientWidth;");

Upvotes: 12

Related Questions