Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 650
machinarium Avatar asked Oct 19 '18 02:10

machinarium


People also ask

Why is my browser window not maximized?

As we know that to maximize the browser window we have used the maximize () method but still, you can see that your window is not maximized, we are getting a WebDriverException for that. As you see the above code there is nothing wrong with the code but when we try to execute the code we are getting an exception and the browser is not maximized.

Is it possible to use chromedriver to maximize browser window?

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.

Does chromedriver resizing/positioning window commands fail on Chrome 62+?

The release notes for ChromeDriver 2.33 says that ""Fixes a bug which caused Resizing/Positioning Window commands to fail on Chrome 62+" however this still seems to be an issue when i am using Chrome 62+ browser. Maximizing chrome window using chrome driver results in below exception.

What does Hyper-V failed to change state mean?

The “Hyper-V failed to change state” message can also contain this phrase: The status cannot be changed. Common reasons for the start/stop VM error are storage failure, incorrect network configuration, Routing and Remote Access configuration, VM power options, and insufficient permissions to access VM files.


2 Answers

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);
    };");
like image 146
Infern0 Avatar answered Sep 27 '22 20:09

Infern0


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:

  • If you are using Chrome version 70 (the current stable release), please download ChromeDriver version 70.0.3538.97 from https://chromedriver.storage.googleapis.com/index.html?path=70.0.3538.97/
  • If you are using Chrome version 71 (the current beta release), please download ChromeDriver version 71.0.3578.33 from https://chromedriver.storage.googleapis.com/index.html?path=71.0.3578.33/

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.
    • Upgrade JDK to recent levels JDK 8u181.
  • Your Selenium Client version is 2.39.0 of 2013-12-16 13:18:38 which is almost 2 years older.
    • Upgrade Selenium to current levels Version 3.14.0.
like image 42
undetected Selenium Avatar answered Sep 27 '22 21:09

undetected Selenium