Skip to content
CodeKruPro

Start Chrome headless with a fixed window size (Java)

QuizEasy-MediumJava onlyAsked in: Capgemini, Cognizant, Infosys, Wipro

Which code starts Chrome without a visible window and with a 1920 by 1080 window in Selenium 4 Java?

  • ChromeOptions o = new ChromeOptions(); o.addArguments("--headless=new", "--window-size=1920,1080"); WebDriver d = new ChromeDriver(o);
  • WebDriver d = new ChromeDriver(); d.setHeadless(true);
  • System.setProperty("headless", "true"); WebDriver d = new ChromeDriver();
  • DesiredCapabilities c = DesiredCapabilities.headless(); new ChromeDriver(c);

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in