Something like driver.manage().window().maximize();
but for minimize the window.
Thanks!
-
IMHO the question is more similar to this one https://stackoverflow.com/questions/42647058/how-to-minimize-browser-window-in-selenium-webdriver-3 than https://stackoverflow.com/questions/52504503/how-to-execute-tests-with-selenium-webdriver-while-browser-is-minimized. @Raclos check out this answer https://stackoverflow.com/a/49801236/4880379 – kasptom Feb 24 '20 at 10:56
-
Does [this](https://stackoverflow.com/a/49801236/4880379) answer your question? [How to Minimize browser window in selenium webdriver 3](https://stackoverflow.com/questions/42647058/how-to-minimize-browser-window-in-selenium-webdriver-3) – kasptom Feb 24 '20 at 10:59
4 Answers
Selenium doesn't have minimize()
option, atleast not for Java, however you can use setPosition
do do it
driver.manage().window().setPosition(new Point(0, 0));
However the better way is to run it as headless browser
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
WebDriver driver = new ChromeDriver(options);
This way you can use maximized browser while it's running in the background.

- 46,488
- 10
- 44
- 88
-
Is there any advantage to use maximized browser in the background instead of the normal sized browser? – Raclos Feb 24 '20 at 11:59
-
1@Raclos Yes, Selenium interaction with the browser depends on the view port, i.e. the visible part. If the window is maximized there is more area you can interact with. – Guy Feb 24 '20 at 12:04
Selenium's java client have no built-in method for minimizing the browser. Ideally, you shouldn't minimize the browser while the Test Execution is In Progress as Selenium would loose the focus over the Browsing Context and an exception will be raised at any point of time which will halt the Test Execution.
You can find a relevant detailed discussion in How to execute tests with selenium webdriver while browser is minimized
However, to mimic the functionality of minimizing the Browsing Context you can use the following solution:
driver.navigate().to("https://www.google.com/");
Point p = driver.manage().window().getPosition();
Dimension d = driver.manage().window().getSize();
driver.manage().window().setSize(new Dimension(0,0));
driver.manage().window().setPosition(new Point((d.getHeight()-p.getX()), (d.getWidth()-p.getY())));

- 183,867
- 41
- 278
- 352
You can set the position of the WebDriver outside of your view. That way, it'll be out of sight while it runs.
FirefoxDriver driver = new FirefoxDriver();
driver.manage().window().setPosition(new Point(-2000, 0));
OR
Dimension windowMinSize = new Dimension(100,100); driver.manage().window().setSize(windowMinSize);
Use below code to completely minimize it.
driver.manage().window().setPosition(new Point(-2000, 0))

- 164
- 1
- 14