我目前在Windows 7操作系统上使用Chrome和Selenium,我尝试使用--no-startup-window
。但是,此选项使Selenium崩溃,并出现以下错误:
Traceback (most recent call last):
File "program_test.py", line 234, in <module>
main()
File "program_test.py", line 36, in main
initChromeWebDriver()
File "c:\opt\project\auto\common\driver.py", line 27, in initChromeWebDriver
driver = webdriver.Chrome("C:\\chromedriver.exe", chrome_options=chrome_options)
File "c:\opt\project\env\lib\site-packages\selenium\webdriver\chrome\webdriver.p
y", line 67, in __init__
desired_capabilities=desired_capabilities)
File "c:\opt\project\env\lib\site-packages\selenium\webdriver\remote\webdriver.p
y", line 91, in __init__
self.start_session(desired_capabilities, browser_profile)
File "c:\opt\project\env\lib\site-packages\selenium\webdriver\remote\webdriver.p
y", line 173, in start_session
'desiredCapabilities': desired_capabilities,
File "c:\opt\project\env\lib\site-packages\selenium\webdriver\remote\webdriver.p
y", line 233, in execute
self.error_handler.check_response(response)
File "c:\opt\project\env\lib\site-packages\selenium\webdriver\remote\errorhandle
r.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to st
art: exited normally
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platfo
rm=Windows NT 6.1.7601 SP1 x86_64)
有我的代码:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-startup-window")
driver = webdriver.Chrome("C:\\chromedriver.exe", chrome_options=chrome_options)
如果没有此选项,Chrome可以在我评论该行时启动。
关于这个问题的任何想法?
答案 0 :(得分:0)
Chrome 59附带“--headless”选项。我在Python 2.7和Selenium 3中使用它。工作就像一个魅力。只需尝试“--headless”代替“--no-startup-window”