Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I start a Selenium browser(like Firefox) minimized?

Tags:

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

like image 647
ionutcib Avatar asked Jul 10 '11 21:07

ionutcib


People also ask

Can Selenium run minimized?

Selenium 4 gives you a brand new method named “minimize()” which can be used to minimize the browser just like a user normally do. “minimize” method is in inner interface “Window” of WebDriver interface.

How does Selenium minimize and maximize windows?

New Selenium IDE We can maximize and minimize the browser while we are testing an application in Selenium. For maximizing the browser, maximize() method is to be used. For minimizing the browser, minimize() method is to be used. Both these methods can be used simultaneously in the same program.

How do I start Selenium maximized?

To maximize browser in Selenium, you need to call the maximize() Selenium command to maximize window interface of the driver class. void maximize() – This method is used to maximize the current browser. You can customize the size of the browser according to the requirement of the scenario.


2 Answers

I have an alternate solution that may meet your needs. 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 may start at a visible location, but it will only be there for an instant.)

FirefoxDriver driver = new FirefoxDriver(); driver.manage().window().setPosition(new Point(-2000, 0)); 
like image 102
NoBrainer Avatar answered Oct 21 '22 23:10

NoBrainer


Your question does not say that why you want to run your test cases in minimized browser but unfortunately selenium do not provide any built-in function for the same.

Normally when we want to run test cases with maximized browser we use driver.manage().window().maximize();

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

One more thing you can try is HtmlUnitDriver.By using this you cant 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.

like image 20
Abhishek_Mishra Avatar answered Oct 21 '22 23:10

Abhishek_Mishra