Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

I'm using Selenium WebDriver for automation and I'm using Chromedriver.

I have noticed that when my driver runs and opens the chrome browser, it opens the browser with a strange size. I tried to fix it but in vain.

Does anybody know how can I change it?

1 Answer

0 votes
by (62.9k points)

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




Java using Chrome options

import org.openqa.selenium.WebDriver;



import org.openqa.selenium.remote.DesiredCapabilities;


public class BrowserOperations {

    public static void main(String[] args) {




        ChromeOptions options = new ChromeOptions();



        DesiredCapabilities cap =;

        cap.setCapability(ChromeOptions.CAPABILITY, options);


        //this will open chrome with set size

        WebDriver driver = new ChromeDriver(capabilities);





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();


Browse Categories