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.
Join Stack Overflow to learn, share knowledge, and build your career.
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.
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();
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);
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
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);");