我们找到了使用Chrome版本69 w / chromedriver 2.43的解决方案,但Chrome仍然坚持要更新自己.
我们运行Selenium-java 3.4,htmlunit-driver 2.27,testng 6.9.4,junit 4.7 with maven-compiler-plugin 3.6.1,maven-surefire-plugin 2.22.0.
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.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 107 milliseconds Build info: version: '3.4.0',revision: 'unknown',time: 'unknown' System info: host: 'edited',ip: 'edited',os.name: 'Mac OS X',os.arch: 'x86_64',os.version: '10.13.6',java.version: '1.8.0_131' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{mobileEmulationEnabled=false,hasTouchScreen=false,platform=MAC,acceptSslCerts=false,goog:chromeOptions={debuggerAddress=localhost:52400},acceptInsecureCerts=false,webStorageEnabled=true,browserName=chrome,takesScreenshot=true,javascriptEnabled=true,setWindowRect=true,unexpectedAlertBehavIoUr=,applicationCacheEnabled=false,rotatable=false,networkConnectionEnabled=false,chrome={chromedriverVersion=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),userDataDir=/var/folders/cd/rrq4w8sd3gz92ygpfx5_kwtw0000gp/T/.org.chromium.Chromium.DCVcH3},takesHeapSnapshot=true,pageLoadStrategy=normal,databaseEnabled=false,handlesAlerts=true,version=70.0.3538.67,browserConnectionEnabled=false,nativeEvents=true,locationContextEnabled=true,cssSelectorsEnabled=true}] Session ID: adb51408a3b04f990288d09604daa3a9 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:215) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:694) at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.maximize(RemoteWebDriver.java:925) at ufis.common.TestSuiteUtils.getDriver(TestSuiteUtils.java:59) at ufis.test.cv.categories.research.independentresearch.IndependentResearchValidationTests.setUpClass(IndependentResearchValidationTests.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:517) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:140) at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748)
解决方法
org.openqa.selenium.WebDriverException: unknown error: Failed to change window state to maximized,current state is normal
…暗示ChromeDriver无法最大化Chrome浏览器客户端的窗口状态.
Buggy Mac OSX ChromeDriver取代了
Chrome版本70发布后,有些人报告说使用ChromeDriver最大化Mac上的浏览器窗口不再有效. ChromeDriver团队已调查此问题,并为其创建了修复程序. ChromeDriver构建版本现已在以下位置提供:
>如果您使用的是Chrome版本70(当前的稳定版本),请从https://chromedriver.storage.googleapis.com/index.html?path=70.0.3538.97/下载ChromeDriver版本70.0.3538.97
>如果您使用的是Chrome版本71(当前测试版),请从https://chromedriver.storage.googleapis.com/index.html?path=71.0.3578.33/下载ChromeDriver版本71.0.3578.33
ChromeDriver发布电子邮件快照
但是,您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:
>您的JDK版本是1.8.0_131,这是非常古老的.
>您的Selenium客户端版本是3.4.0,差不多一年了.
>将Selenium升级到当前级别Version 3.14.0.
从另一个角度来看,这个问题看起来像是从Feature request : ChromeDriver to support window resizing over a remote connection开始的回归问题.
Release Notes中的ChromeDriver v2.43明确提到:
ChromeDriver to support window resizing over a remote connection
但是,根据最大化Chrome浏览器客户端的最佳做法,建议使用ChromeOptions类,如下所示:
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");
参考
您可以在driver.manage().window().maximize() issue with ChromeDriver 2.33找到详细的讨论
更新(2018年11月20日)
> ChromeDriver 2.44已发布.> ChromeDriver 2.44支持Chrome版本69到71>此版本与ChromeDriver 2.43类似,但还有其他错误修复.>支持chrome 72.x的ChromeDriver预计将于12月初发布.