使用Chrome60启动selenium chromedriver失败

时间:2017-08-30 07:23:32

标签: java selenium selenium-chromedriver

详细错误日志如下:

TESTFAIL; com.ibm.test.inotes.authentication.LoginTestCase; 
org.openqa.selenium.WebDriverException: unknown error: failed to change window state to normal, current state is maximized
(Session info: chrome=60.0.3112.113)
(Driver info: chromedriver=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262),platform=Mac OS X 10.12.0 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 104 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'inotess-imac.cn.ibm.com', ip: '9.123.154.177', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12', java.version: '1.8.0_74'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262), userDataDir=/var/folders/k5/7h9wrl411lscklkysfgpdj3r0000gn/T/.org.chromium.Chromium.4Yvm6j}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=60.0.3112.113, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 1fad624912a4ca9ed46ea749eef0521c
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:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:6
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:891)
at appobjects.web.Browser.setSize(Browser.java:420)
at appobjects.web.Browser.maximize(Browser.java:520)
at com.ibm.test.inotes.iNotesTestCase.testSetUp(iNotesTestCase.java:626)
at com.ibm.test.BaseTestCase.before(BaseTestCase.java:30)
at com.ibm.test.inotes.iNotesTestSuiteRunner.runChild(iNotesTestSuiteRunner.java:151)
at com.ibm.test.inotes.iNotesTestSuiteRunner$1.evaluate(iNotesTestSuiteRunner.java:240)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:77)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
at com.ibm.test.inotes.suite.SuiteLauncher.main(SuiteLauncher.java:167)

3 个答案:

答案 0 :(得分:0)

正如错误日志所示

failed to change window state to normal, current state is maximized

我建议在iNotesTestCase.testSetUp中,在调用setSize方法之前删除调用最大化。

另一方面,我还建议升级到最新的chromedriver分期付款v2.31(https://sites.google.com/a/chromium.org/chromedriver/downloads)。

答案 1 :(得分:0)

由于您在无头模式下运行测试,因此没有可用的活动浏览器窗口。就这样你的

   driver.manage().window().maximize()
在这种情况下,

总是会失败,因为驱动程序并不知道哪个窗口要最大化,因为没有任何可用的窗口。

尝试这样的事情

 driver.manage().window().setSize(new Dimension(1440, 900));

答案 2 :(得分:0)

错误堆栈跟踪将其全部表示为:

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

当您尝试通过以下方式最大化Chrome浏览器时会出现此错误:

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

您可以浏览GitHub discussionchromedriver issue了解详情。

IMO,没有最佳做法,但您始终可以考虑使用Options类来最大化Chrome浏览器窗口,如下所示:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()