擅长:python、mysql、java
<p>这里是@Florent B的<strong>Java</strong>版本。答案:</p>
<pre><code> int width = "500";
int height = "500";
//Remove the window from fullscreen (optional), if it s in fullscreen the outerHeight is not accurate
browser.manage().window().setSize(new Dimension(800,800));
JavascriptExecutor js= (JavascriptExecutor)browser;
String windowSize = js.executeScript("return (window.outerWidth - window.innerWidth + "+width+") + ',' + (window.outerHeight - window.innerHeight + "+height+"); ").toString();
//Get the values
width = Integer.parseInt(windowSize.split(",")[0]);
height = Integer.parseInt(windowSize.split(",")[1]);
//Set the window
browser.manage().window().setSize(new Dimension(width, height));
</code></pre>