python - no-startup-window 选项在 Windows 上不起作用

标签 python google-chrome selenium

嗨!

我目前在 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 可以在我评论该行时启动。

关于这个问题有什么想法吗?

最佳答案

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

关于python - no-startup-window 选项在 Windows 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39569128/

相关文章:

java - 如何使用 Selenium 注入(inject) XML 文件?

c# - Selenium 2 WebDriver 未按预期评估更新的 DOM

python - 如何遍历字符串中的所有字符?

Python C API sys.getsizeof()

python - 在 python 中捕获复杂 shell 命令的输出

javascript - 如何将 Node js native 模块注入(inject) puppeteer 页面

python - 如何在 Django 模型中按不同模型中的字段降序排序?

css - Microsoft Sitka 字体不适用于 Chrome 和 Firefox

windows - 是否可以为 windows 映射 Vim 键绑定(bind),就像 chrome 的 vimium 一样

selenium - WebDriver takeScreenshot() 返回空白屏幕