0

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.

thewaywewere
  • 8,128
  • 11
  • 41
  • 46
  • Possible duplicate of [How to Maximize a firefox browser window using Selenium WebDriver with node.js](https://stackoverflow.com/questions/14052173/how-to-maximize-a-firefox-browser-window-using-selenium-webdriver-with-node-js) – JeffC Oct 27 '17 at 13:23
  • 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 01 '17 at 19:16

7 Answers7

1

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);
Davide Patti
  • 3,391
  • 2
  • 18
  • 20
  • even better though `Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();` since this would be a "true" maximize instead of an arbitrary width/height – ddavison Oct 27 '17 at 17:41
  • @sircapsalot You are right, I inserted your improvement. – Davide Patti Oct 27 '17 at 17:55
1

This is how I did it.

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--start-maximized");
    WebDriver driver = new ChromeDriver(chromeOptions);
njosep
  • 380
  • 3
  • 14
0
//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);");
Samir 007
  • 179
  • 2
  • 8
0

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.

Guillermo Mestre
  • 490
  • 3
  • 16
0

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);
JackForman
  • 61
  • 2
0

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

Harry King
  • 502
  • 4
  • 15
0

Try following code:

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