从Chrome位置C:\..\Chrome\Application\chrome.exe启动的进程不再运行,因此ChromeDriver假设Chrome已崩溃

af7jpaap  于 2023-02-17  发布在  Go
关注(0)|答案(5)|浏览(264)

Chrome版本:68.0.3440.106
Chrome网页驱动程序版本:Chrome驱动程序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)
dzhpxtsq

dzhpxtsq1#

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

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

uqcuzwp82#

今天我是同样的麻烦,我修复使用:

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

cld4siwp3#

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

ltskdhd1

ltskdhd14#

此错误消息...

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无法启动/生成新的WebBrowser,即Chrome浏览器会话。
您的主要问题似乎是chrome二进制文件(即chrome.exe)和关联文件无法从以下默认位置获得/访问:

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

可能的原因是:

  • 之前安装在默认位置的Chrome浏览器损坏/删除
  • 如果您在非标准位置安装了 *Chrome浏览器 *,您需要执行以下操作:
opt = webdriver.ChromeOptions()
opt.binary_location("/path/to/other/chrome/binary");

其他注意事项

  • ChromeChromeDriver 位于所需位置。
  • ChromeChromeDriver 对非root(非管理员)用户具有可执行权限。
  • Selenium 升级至当前等级Version 3.14.0
  • 通过您的 IDE**清理 * 您的 * 项目工作区 *,并仅使用必需的依赖项 * 重建 * 您的项目。
  • (* 仅限WindowsOS *)在执行 * 测试套件 * 前后,使用CCleaner工具清除所有操作系统杂务。
  • (* 仅限LinuxOS *)执行 * 测试套件 * 之前和之后的Free 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服务器)。
piv4azn7

piv4azn75#

我们在使用Java、Cucumber、Maven、Serenity和IntelliJ时遇到了这个问题。尝试了所有方法后,解决方案非常简单:
只需以管理员身份运行IntelliJ。

相关问题