【问题标题】:The process started from chrome location C:\..\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed从 chrome 位置 C:\..\Chrome\Application\chrome.exe 开始的进程不再运行,因此 ChromeDriver 假设 Chrome 已崩溃
【发布时间】:2018-08-24 17:37:59
【问题描述】:

Chrome 版本:68.0.3440.106
Chrome 网络驱动程序版本:ChromeDriver 2.41.578737
Python版本:Python 3.5.2

我用python写了这段代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys


o = webdriver.ChromeOptions()
o.add_argument("disable-extensions");
o.add_argument("--start-maximized");
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

几秒钟后,chrome 打开并出现此错误:


直到我关闭 chrome 并得到这个异常之前什么都没有发生:

    Traceback (most recent call last):
  File ".../game.py", line 8, in <module>
    driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
  File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
  (unknown error: unable to discover open pages)
  (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)

【问题讨论】:

标签: python selenium google-chrome selenium-webdriver selenium-chromedriver


【解决方案1】:

我最近在使用 TeamCity 时遇到了这个问题,这是由于 chrome(和 chromedriver)在执行我的脚本后没有关闭造成的。 插入“taskkill /f /im chrome.exe”和“taskkill /f /im chromedriver.exe”修复了这个问题。

【讨论】:

    【解决方案2】:

    今天我遇到了同样的麻烦,我使用以下方法解决了:

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    
    o = webdriver.ChromeOptions()
    o.add_argument("disable-extensions")
    o.add_argument("--start-maximized")
    o.binary_location = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ## This line define path of browser. In this case, Google Chrome
    driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
    driver.get("http://www.python.org")
    assert "Python" in driver.title
    elem = driver.find_element_by_name("q")
    elem.clear()
    elem.send_keys("pycon")
    elem.send_keys(Keys.RETURN)
    assert "No results found." not in driver.page_source
    driver.close()
    

    【讨论】:

    • 您能解释一下您更改了哪个部分来解决此问题吗?
    • Oliver,添加这一行:o.binary_location = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ## 这行定义浏览器的路径。在这种情况下,谷歌浏览器
    【解决方案3】:

    使用正确的参数来禁用扩展:

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.chrome.options import Options
    o = Options()
    #o.add_argument("--disable-extensions"); #here
    o.add_experimental_option("useAutomationExtension", false); #you can try this as well
    o.add_argument("--start-maximized");
    driver = webdriver.Chrome(executable_path=r"chromedriver.exe",chrome_options=o)
    driver.get("http://www.python.org")
    assert "Python" in driver.title
    elem = driver.find_element_by_name("q")
    elem.clear()
    elem.send_keys("pycon")
    elem.send_keys(Keys.RETURN)
    assert "No results found." not in driver.page_source
    driver.close()
    

    【讨论】:

    • 你可以多尝试一个选项:o.setExperimentalOption("useAutomationExtension", false);此功能将有助于不加载 Chrome 自动化扩展。我已经更新了我的答案。
    • 还是不行,在python中是o.add_experimental_option("useAutomationExtension", False)
    • 我的错,你是对的。我把python和java混在一起了。顺便说一句,您仍然遇到同样的错误吗?
    【解决方案4】:

    此错误消息...

    selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
      (unknown error: unable to discover open pages)
      (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    

    ...暗示 ChromeDriver 无法启动/生成新的 WebBrowserChrome 浏览器 会话。

    您的主要问题似乎是 chrome 二进制文件,即 chrome.exe 和相关文件不再可用/无法从以下默认位置访问:

    C:\Program Files (x86)\Google\Chrome\Application\
    

    可能的原因有:


    其他注意事项

    • ChromeChromeDriver 存在于所需位置。
    • ChromeChromeDriver 对非 root(非管理员)用户具有可执行权限。
    • Selenium升级到当前级别Version 3.14.0
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖。
    • 仅限 Windows 操作系统)使用 CCleaner 工具在执行您的测试套件之前和之后清除所有操作系统琐事。
    • 仅限 LinuxOSFree Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint 在执行您的测试套件之前和之后。
    • 如果您的基础 Web Client 版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web Client
    • 进行系统重启
    • 非root用户身份执行@Test
    • 在带有桌面的机器上使用webdriver-manager start 运行 selenium 服务器(不要使用远程会话来启动 selenium 服务器)。

    【讨论】:

    • Chrome 已打开,但在我关闭窗口后(经过很长时间没有任何响应,但出现错误消息)我收到此异常,您的回答对我没有任何帮助,但感谢试试看。
    猜你喜欢
    • 2019-09-01
    • 2021-12-19
    • 2022-01-24
    • 2019-09-15
    相关资源
    最近更新 更多