我正在使用Selenium Java自动化一些测试,我想获取整个窗口的大小(不带地址栏的浏览器大小)
我试图使用driver()。manage()。window()。getSize(),但是这获取了包括地址栏在内的窗口的高度。
最后发布: 2019-09-08 10:22:54
我正在使用Selenium Java自动化一些测试,我想获取整个窗口的大小(不带地址栏的浏览器大小)
我试图使用driver()。manage()。window()。getSize(),但是这获取了包括地址栏在内的窗口的高度。
您可以在html
标记上使用getSize()
driver.findElement(By.tagName("html")).getSize();
您可以尝试这种方法:
private static Long getHeight(JavascriptExecutor driver) {
return (Long) (driver.executeScript("return window.innerHeight || document.body.clientHeight"));
}
private static Long getWidth(JavascriptExecutor driver) {
return (Long) (driver.executeScript("return window.innerWidth || document.body.clientWidth"));
}