Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to maximize Chrome Window in headless mode

I recently upgraded my chrome version to 60 and chromedriver to version 2.31. Post that I have started getting the following exception when I try to do a maximize of the browser window.

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

org.openqa.selenium.WebDriverException: unknown error: failed to change window state to maximized, current state is normal (Session info: chrome=60.0.3112.78) (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.2.0-27-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 108 milliseconds Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09' System info: host: 'bb-blr-prod-stage-stg1-01', ip: '10.3.211.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-27-generic', java.version: '1.7.0_80' Session ID: c7de7149dd490cc7760d2f4fc49f0325 Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.org.chromium.Chromium.WABPhO, chromedriverVersion=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, setWindowRect=true, locationContextEnabled=true, mobileEmulationEnabled=false, pageLoadStrategy=normal, version=60.0.3112.78, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]

I run my tests in headless mode using ChromeDriver on Geb.

  • Chrome version - 60.0.3112.78
  • chromedriver version - 2.31.488763
  • OS - Ubuntu 14.04.4 LTS
  • Selenium version - 2.53.1
  • WebDriver Language Bindings
  • Geb - 0.13.1
like image 236
Pinaki Avatar asked Jul 28 '17 13:07

Pinaki


2 Answers

Since you're running tests in a headless mode, there is no active browser window available. As such your

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

would always fail in such situations because the driver doesn't know which window to maximize since there aren't any available.

You can either follow what @DebanjanB has mentioned or you can start the headless browser with a specific screen size like 1440x900 etc, doing something like this

 driver.manage().window().setSize(new Dimension(1440, 900));
like image 58
demouser123 Avatar answered Sep 24 '22 03:09

demouser123


Add below ChromeOption in your code :

options.addArguments("--window-size=1325x744");

Also refer this blog for more

like image 29
NarendraR Avatar answered Sep 20 '22 03:09

NarendraR