Would anyone know how to maximize the selenium webdriver window with java and google chrome.

I already tried some commands like maximize () window () and did not work.

  • What version of ChromeDriver and Selenium are you using? – smit9234 Oct 27 '17 at 13:38
  • JeffC - I had already visualized this question but I am not using the node.js I tried the commands described in it and did not work. – Anderson Builder Oct 27 '17 at 13:39
  • smit9234# ChromeDriver> 2.25 selênio> 3.6 – Anderson Builder Oct 27 '17 at 13:41
  • It sounds like ChromeDriver might be out of date (assuming Chrome is able to automatically update). You should consider using the latest version of ChromeDriver. – Harry King Nov 1 '17 at 19:16

Try following code:

            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized"); //This maximizes the window
            options.setExperimentalOption("prefs", chromePrefs);
            WebDriver driver = new ChromeDriver(options);

You can do this using the WebDriver API, and this will work with other browsers and RemoteWebDriver:

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

https://stackoverflow.com/a/26998387/5603509

Try with this:

        String chromeDriver = "/PathTo/chromedriver";
        System.setProperty("webdriver.chrome.driver", chromeDriver);

        ChromeDriver driver = new ChromeDriver();

        //set your max dimension
        java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension dim= new Dimension((int)screenSize.getWidth(),(int)screenSize.getHeight());

        driver.manage().window().setSize(dim);
  • even better though Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); since this would be a "true" maximize instead of an arbitrary width/height – sircapsalot Oct 27 '17 at 17:41
  • @sircapsalot You are right, I inserted your improvement. – Davide Patti Oct 27 '17 at 17:55

If you're using a Mac you'll need to use the following

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(chromeOptions);

This is how I did it.

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--start-maximized");
    WebDriver driver = new ChromeDriver(chromeOptions);

You can try too sending keystrokes:

SendKeys(Keys.ALT, " "); // Space, open window menu    
SendKeys("x"); // Maximize

Include a pause between keystrokes, although it could work for you without it.

//Maximizing Chrome Window.
int x=1280; //according to your screen resolution
int y=860;  //according to your screen resolution
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("window.resizeTo(x, y);");

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.