我试图用一个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中一切都很好
I started seeing this problem on Monday 2018-06-04. Our tests run each weekday. It appears that the only thing that changed was the google-chrome version (which had been updated to current) JVM and Selenium were recent versions on Linux box ( Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62, and xvfb-run).
Specifically adding the arguments "--no-sandbox" and "--disable-dev-shm-usage" stopped the error.
I'll look into these issues to find more info about the effect, and other questions as in what triggered google-chrome to update.
ChromeOptions options = new ChromeOptions();
...
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
在我的情况下,我试图用chrome浏览器在Windows操作系统上创建一个可运行的jar,并希望在unix盒子上运行CentOs的无头模式。我把二进制文件指向一个我已经下载并打包在我的套件中的驱动程序。对我来说,这个问题继续发生,不管添加以下内容:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
options.setBinary("/pointing/downloaded/driver/path/in/automationsuite");
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("window-size=1024,768"); // Bypass OS security model
options.addArguments("--log-level=3"); // set log level
options.addArguments("--silent");//
options.setCapability("chrome.verbose", false); //disable logging
driver = new ChromeDriver(options);
我尝试过并为我工作的解决方案是,在主机VM/Unix盒子上下载chrome及其工具,在自动化套件中安装并指向此二进制文件,然后就完成了!它是有效的:)
下载命令:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
安装命令:
sudo yum install -y ./google-chrome-stable_current_*.rpm
更新套件包含以下google-chrome二进制路径:
options.setBinary("/opt/google/chrome/google-chrome");
和. .它的工作原理!
我的问题是php-webdriver中的一个bug。我的代码是:
$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments([
'--headless',
'--no-sandbox',
'--disable-gpu',
'--disable-dev-shm-usage',
'--no-proxy-server'
]);
$chromeOptions->setExperimentalOption('detach', true);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(
ChromeOptions::CAPABILITY,
$chromeOptions
);
如你所见,一切都符合其他可能的原因。
但实际上这些功能并没有传递给chromedriver。我不得不改变设置chrome选项功能:
$capabilities->setCapability(
ChromeOptions::CAPABILITY_W3C, // <<< Have to use W3C capabilities with recent versions of Chromedriver.
$chromeOptions->toArray() // <<<<< bug in php-webdriver 1.9, object not getting serialized automatically like with the deprecated capability ChromeOptions::CAPABILITY
);
我的设置是:
$ chromedriver --version
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614})
$ java -jar selenium-server-standalone-3.141.59.jar --version
Selenium server version: 3.141.59, revision: e82be7d358
做了一个bug报告和一个PR来修复php-webdriver中的这个bug
https://github.com/php-webdriver/php-webdriver/issues/849
我遇到了同样的问题,在我的情况下,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。