machinarium
machinarium

Reputation: 681

WebDriverException: unknown error: failed to change window state to maximized, current state is normal with ChromeDriver v2.43 and Chrome 70 on MacOSX

My macOS just upgraded chrome automatically to v70, I upgraded chromedriver to latest version accordingly, however, my Selenium automation tests can't run due to below error when invoking

tempDriver.manage().window().maximize();

Error message is

org.openqa.selenium.WebDriverException: unknown error: failed to change window state to maximized, current state is normal
  (Session info: chrome=70.0.3538.67)
  (Driver info: chromedriver=2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8),platform=Mac OS X 10.14.0 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 111 milliseconds
Build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38'
System info: host: 'jingfeideMacBook-Pro.local', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=MAC, acceptSslCerts=false, goog:chromeOptions={debuggerAddress=localhost:58298}, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8), userDataDir=/var/folders/mc/p32y5m3503b8qrq4nv3fjc280000gn/T/.org.chromium.Chromium.tp2flf}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, version=70.0.3538.67, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
Session ID: 5010a1722b23e3829ebcb8b45ceab234
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.maximize(RemoteWebDriver.java:783)

Any thoughts? I know the version of Selenium is a little bit old but i can't upgrade it due to corporate policy or something.

Balin

Upvotes: 5

Views: 6016

Answers (4)

Dejy Joy
Dejy Joy

Reputation: 11

observed this issue when running package suite and tried ChromeOptions but didnt work.So have tried this way and worked for me

   Dimension ExpectedDimension=new Dimension(Screen dimensions accordingly)
   Dimension Before_Maximising= Driver.manage().window().getSize();
   Logging.info("Before_Maximising"+Before_Maximising);

   if(Before_Maximising.equals(ExpectedDimension)) {
    Logging.info("Already maximised");
   }

   else {

   Driver.manage().window().setSize(ExpectedDimension);
   Dimension After_Maximising = Driver().manage().window().getSize();
   Logging.info("After_Maximising"+After_Maximising);
   }

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193058

This error message...

org.openqa.selenium.WebDriverException: unknown error: failed to change window state to maximized, current state is normal

...implies that the ChromeDriver was unable to maximize the window state of Chrome Browser client.

Not sure how this issue made way with ChromeDriver v2.43 and Chrome Browser v70.0 combination but look like a regression issue for Feature request : ChromeDriver to support window resizing over a remote connection.

ChromeDriver v2.43 in the Release Notes have explicitly mentioned:

Resolved issue 1855: Feature request : ChromeDriver to support window resizing over a remote connection [[Pri-2]]


Buggy Mac OSX ChromeDriver Replaced

After Chrome version 70 was released, some of you have reported that using ChromeDriver to maximize browser window on Mac no longer works. ChromeDriver Team have investigated this issue, and created a fix for it. ChromeDriver builds with the fix are now available at the following locations:

Snapshot of ChromeDriver Release Email:

ChromeDriver_new


However, as per best practices to maximize the Chrome Browser client it is suggested to use ChromeOptions class as follows:

System.setProperty("webdriver.chrome.driver", "C:\\your_directory\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-infobars");
opt.addArguments("--start-maximized");
opt.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(opt);
driver.get("https://google.com");

You can find a detailed discussion in driver.manage().window().maximize() issue with ChromeDriver 2.33


Additional Consideration

  • Your JDK version is 1.8.0_111 which is pretty ancient.
  • Your Selenium Client version is 2.39.0 of 2013-12-16 13:18:38 which is almost 2 years older.

Upvotes: 3

River
River

Reputation: 1

We encountered the same issue, the workaround is to comment out the code:

tempDriver.manage().window().maximize();

Upvotes: 0

Infern0
Infern0

Reputation: 2814

Until issue is resolved you can bypass this with:

Custom window size

driver.manage().window().setSize(new Dimension(1920, 1080));

You can get screen resolution

Toolkit toolkit = Toolkit.getDefaultToolkit();
int width = (int) toolkit.getScreenSize().getWidth();
int height = (int) toolkit.getScreenSize().getHeight();

Argument to chrome

ChromeOptions options = new ChromeOptions();
options.addArgument("--start-maximized");

Javascript Executor

((JavascriptExecutor) driver).executeScript("if(window.screen){
    window.moveTo(0, 0);
    window.resizeTo(window.screen.availWidth, window.screen.availHeight);
    };");

Upvotes: 3

Related Questions