Reputation: 9
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.
Upvotes: 0
Views: 3340
Reputation: 842
Try following code:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized"); //This maximizes the window
options.setExperimentalOption("prefs", chromePrefs);
WebDriver driver = new ChromeDriver(options);
Upvotes: 0
Reputation: 512
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
Upvotes: 0
Reputation: 3461
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);
Upvotes: 1
Reputation: 61
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);
Upvotes: 0
Reputation: 380
This is how I did it.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
Upvotes: 1
Reputation: 490
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.
Upvotes: 0
Reputation: 179
//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);");
Upvotes: 0