【问题标题】:The no-startup-window option does not working on Windowsno-startup-window 选项在 Windows 上不起作用
【发布时间】:2016-09-19 08:57:39
【问题描述】:

嗨!

我目前在 Windows 7 操作系统上使用带有 Selenium 的 Chrome,我尝试使用 --no-startup-windowwith。但是,此选项使 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 就可以启动。

关于这个问题的任何想法?

【问题讨论】:

  • 嗨,你能解决这个问题吗?
  • @pratibha:不幸的是,我放弃了。我想您可能需要为他们的 Web 驱动程序打开一张 Chrome 的票...如果您在研究后找到解决方案,请发布答案,我会很感兴趣 :)

标签: python google-chrome selenium


【解决方案1】:

Chrome 59 带有“--headless”选项。我将它与 Python 2.7 和 Selenium 3 一起使用。效果很好。只需尝试“--headless”代替“--no-startup-window”

【讨论】:

  • 好的,Chrome 59 升级后我会尽快尝试 :)
  • 确认它仍然适用于 chrome v80。不推荐使用“--no-startup-window”,以及webdriver.Chrome中的“chrome_options”参数,只使用“options”代替。
猜你喜欢
  • 2020-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-29
  • 2015-08-31
  • 1970-01-01
相关资源
最近更新 更多