Asserting the presence of scrollbar using Selenium

2020-07-09 10:29发布

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?

1条回答
神经病院院长
2楼-- · 2020-07-09 11:10

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;");
查看更多
登录 后发表回答