2017-08-30 121 views
1

詳細的錯誤日誌如下:啓動硒chromedriver失敗,Chrome60

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) 
+0

,我們可以看看,你已經嘗試的代碼? –

回答

0

由於您在無頭模式下運行測試,因此沒有可用的活動瀏覽器窗口。因此您的

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

在這種情況下總是會失敗,因爲驅動程序不知道哪個窗口最大化,因爲沒有任何可用的。

嘗試這樣的事情

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

謝謝,我用setSize方法替換最大化() –

+0

它適合你嗎? –

+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)。

+0

我已經嘗試使用chromedriver 2.31和2.30,遇到同樣的錯誤 –

+0

@ xiaona2016cao嘗試執行其他用戶推薦的內容並編輯最大化呼叫。 –

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瞭解更多詳情ILS。

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()