selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
(chrome not reachable)
(The process started from chrome location C:\Users\XXX\AppData\Local\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
# 启动浏览器
url = "https://baidu.com"
driver.get(url)
print(driver.title)
# 关闭浏览器
driver.quit()
if __name__ == "__main__":
run_code = 0
添加上述参数,即可正常使用selenium打开浏览器。
解决Selenium运行时Chrome崩溃的问题
文章描述了在使用Selenium进行Web自动化测试时遇到Chrome浏览器崩溃的问题,给出了错误信息。解决方案是通过添加特定的Chrome选项如--no-sandbox,--disable-gpu和--disable-dev-shm-usage来防止崩溃,并提供了一段示例代码展示如何配置这些选项来正常启动浏览器并访问网页。
31万+

被折叠的 条评论
为什么被折叠?



