1

I am trying to open the chrome browser with devtools open in maximized window. Following code does not work, driver opens the URL in a smaller window without devtools.

System.setProperty("webdriver.chrome.driver", "<path to chrome.exe>");

ChromeOptions options = new ChromeOptions();        
<String> chromeoptions = new ArrayList<String>();
chromeoptions.add("start-maximised");
chromeoptions.add("auto-open-devtools-for-tabs");
options.addArguments(chromeoptions);

WebDriver driver=new ChromeDriver(options);

driver.get("http://www.google.com");

I have also used Capabilities with no result.

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.binary", "<path to chrome exe>");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);      
WebDriver driver=new ChromeDriver(capabilities);

I am using Chrome 75, selenium jar version 3.4.0

Any suggestion?

Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
Jai S
  • 41
  • 1
  • 5
  • Arguments should be `--start-maximized` and not `start-maximised`. You are missing `--` and have a typo in word `maximized`. The same `--` probably applies for the second argument as well – Fenio Jul 11 '19 at 07:52
  • Thanks Fenio. Did all possible combination. Also corrected spelling. Still no luck. – Jai S Jul 12 '19 at 05:21
  • Try `driver.manage().window().setSize(new Dimension(1920, 1080));` – Fenio Jul 12 '19 at 05:31
  • Hi Fenio, I changed the driver version to 3.0.0. Started working with the previous code. – Jai S Jul 12 '19 at 08:19

3 Answers3

2

As per your code, there have some spelling mistake like("start-maximised") instead of ("--start-maximized")

kindly use the below code:

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--auto-open-devtools-for-tabs");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

WebDriver driver = new ChromeDriver(capabilities);
Amit Singh
  • 121
  • 5
  • Hi Amit,I have tried this also with no luck. Can you please tell me what version of the selenium jar you are using. I am thinking that might be the issue. – Jai S Jul 12 '19 at 05:17
  • I'm using latest version of selenium i.e. 3.14. and it's working fine with me. – Amit Singh Jul 13 '19 at 07:09
1

Update: I changed selenium version to 3.0.0 and It started working.

Jai S
  • 41
  • 1
  • 5
0

Try using chrome options like this. it'll download the correct chrome driver version automatically and also chrome options work correctly.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument("--start-maximized")

driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)

driver.get('https://www.facebook.com/');
Hishan_98
  • 194
  • 1
  • 2
  • 12