Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

How could I start a Selenium browser (like Firefox) minimized? I want the command browser.start(mySettings) to start a browser minimized.

 

 

1 Answer

0 votes
by (62.9k points)

Your question does not state why you want to run your test cases in a minimized browser but unfortunately, Selenium does not provide any built-in function for the same.

Normally when we want to run test cases with the maximized browser we use:

driver.manage().window().maximize();

No doubt there are several ways to minimize your window through code by using Java key events by using keyboard shortcuts for minimizing the window or by using JavaScriptExecuter but that too depending on which OS and language you are working.

One more thing you can try is HtmlUnitDriver.By using this you can't even see the browser, so that may also serve your purpose if you have a case of not opening the browser while execution of test cases.

However, I have an alternate solution that you can try. You can set the position of the WebDriver to be outside of your view. That way, it'll be out of sight while it runs. (It will start at a visible location, but it will be there only for an instant.)

FirefoxDriver driver = new FirefoxDriver();

driver.manage().window().setPosition(new Point(-2000, 0));

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium automation online training

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...