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

SeleniumAutomation TestingTesting Tools

We can start the Selenium browser(like Firefox) in minimized mode. This will be achieved by taking the help of the Dimension class. We shall create an object of this class.

While creating the object , we shall pass the dimensions of the browser size as parameters to the Dimension class. Finally pass the object as parameter to the setSize method.

Syntax

Dimension s = new Dimension(100,200);
driver.manage().window().setSize(s);

Example

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Dimension;
public class FirefoxBrwSize{
   public static void main(String[] args) {
      System.setProperty("webdriver.gecko.driver",
         "C:\\Users\\ghs6kor\\Desktop\\Java\\geckodriver.exe");
      WebDriver driver = new FirefoxDriver();
      //implicit wait time
      driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
      //set browser Dimension
      Dimension s = new Dimension(100,200);
      //set size to browser
      driver.manage().window().setSize(s);
      driver.get("https://www.tutorialspoint.com/index.htm");
      // obtain window size
      System.out.println("Firefox browser size: " +
      driver. manage().window().getSize());
      driver.quit();
   }
}

Output

Browser window −

raja
Published on 30-Jan-2021 13:03:40
Advertisements