我试图用一个URL启动chrome浏览器,浏览器启动后,它什么也不做。
1分钟后我看到如下错误:
Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
我的配置:
Chrome浏览器:66
ChromeBrowser: 2.39.56
又及,在Firefox中一切都很好
我遇到了同样的问题,在我的情况下,Linux系统中有两个不同的常见用户userera和userB。
userA第一次运行selinium程序成功启动chrome浏览器,当到达userB时,出现DevToolsActivePort文件不存在的错误。
我尝试了——remote-debug -port=9222选项,但它导致了一个新的异常:
selenium.common.exceptions.WebDriverException: Message: chrome不可达
I run google-chome目录,看到以下错误:
mkdir /tmp/Crashpad/new: Permission denied (13)
我搜索了这个问题,得到了这个:
https://johncylee.github.io/2022/05/14/chrome-headless-%E6%A8%A1%E5%BC%8F%E4%B8%8B-devtoolsactiveport-file-doesn-t-exist-%E5%95%8F%E9%A1%8C/
chrome_options.add_argument(f"--crash-dumps-dir={os.path.expanduser('~/tmp/Crashpad')}")
感谢@johncylee。
更新conf.js中的功能
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js'],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
}
},
};
我在Ubuntu 20和Python Selenium上遇到了这个问题,我首先单独下载了chromedriver,然后使用sudo apt install chromium-browser,尽管它们是同一个版本,但这种情况一直发生。
我的修复是使用提供的chrome驱动程序,附带的回购包位于
/snap/bin/chromium.chromedriver
driver = webdriver.Chrome(chrome_options=options, executable_path='/snap/bin/chromium.chromedriver')
正如在另一个答案中所述:
此错误消息…这意味着ChromeDriver无法启动/生成一个新的WebBrowser,即Chrome浏览器会话。
Among the possible causes, I would like to mention the fact that, in case you are running an headless Chromium via Xvfb, you might need to export the DISPLAY variable: in my case, I had in place (as recommended) the --disable-dev-shm-usage and --no-sandbox options, everything was running fine, but in a new installation running the latest (at the time of writing) Ubuntu 18.04 this error started to occurr, and the only possible fix was to execute an export DISPLAY=":20" (having previously started Xvfb with Xvfb :20&).