Resize Browser Window in WebDriver
Java using Dimension
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.Dimension;
public class BrowserOperations {
WebDriver driver;
//this will open browser with default size
public void launchBrowser() {
driver = new FirefoxDriver();
}
public void resizeBrowser() {
Dimension d = new Dimension(800,480);
//Resize current window to the set dimension
driver.manage().window().setSize(d);
}
}
Java using Chrome options
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class BrowserOperations {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver";,
"/path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=800,480");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
//this will open chrome with set size
WebDriver driver = new ChromeDriver(capabilities);
driver.get("https://www.intellipaat.com/");
}
}
If you want to maximize the browser window to the maximum width and height of the screen, you can just call the maximize() method
Webdriver driver = new FirefoxDriver();
driver.manage().window().maximize()