使用Selenium断言滚动条的存在(Webdriver Java Cucumber) [英] Asserting the presence of scrollbar using Selenium (webdriver java cucumber)
本文介绍了使用Selenium断言滚动条的存在(Webdriver Java Cucumber)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个需要测试的响应式网站。如果网站转到平板电脑的窗口大小,我希望测试检查是否有水平滚动条。根据设计,它们永远不会出现在平板电脑上。 ?
解决方案
您可以使用 javascriptExecutor
进行测试:
垂直滚动条:
boolean scrollBarPresent =(((JavascriptExecutor)driver).executeScript( 返回document.documentElement.scrollHeight> document.documentElement.clientHeight;);
水平滚动条:
boolean scrollBarPresent =(((JavascriptExecutor)driver).executeScript( return document.documentElement.scrollWidth> document.documentElement.clientWidth;);
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?
解决方案
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;");
这篇关于使用Selenium断言滚动条的存在(Webdriver Java Cucumber)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文