首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP + Selenium :在使用驱动程序服务创建会话时出错。停止驱动程序服务:无法启动新会话

PHP + Selenium :在使用驱动程序服务创建会话时出错。停止驱动程序服务:无法启动新会话
EN

Stack Overflow用户
提问于 2022-07-22 16:16:18
回答 2查看 344关注 0票数 0

我正在尝试让一个带有Selenium + PHP的Debian再次运行。几个月前起作用了。

我尝试以Nginx用户和root用户的身份运行Selenium (在ssh连接中)。两者都会产生相同的错误

代码语言:javascript
运行
复制
java -jar ./selenium-server-4.1.1.jar standalone
代码语言:javascript
运行
复制
Starting ChromeDriver 97.0.4692.71 (adefa7837d02a07a604c1e6eff0b3a09422ab88d-refs/branch-heads/4692@{#1247}) on port 53084
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
12:10:51.070 WARN [SeleniumSpanExporter$1.lambda$export$0] - {"traceId": "a82ccdad343550c9da81ad23dd3c99fb","eventTime": 1658506251052025402,"eventName": "exception","attributes": {"driver.url": "http:\u002f\u002flocalhost:53084","exception.message": "Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location \u002fusr\u002fbin\u002fgoogle-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)\nBuild info: version: '4.1.1', revision: 'e8fcc2cecf'\nSystem info: host: 'selenium.questiondevelopment.com', ip: '43.35.51.12', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.0-18-amd64', java.version: '11.0.13'\nDriver info: driver.version: unknown","exception.stacktrace": "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location \u002fusr\u002fbin\u002fgoogle-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)\nBuild info: version: '4.1.1', revision: 'e8fcc2cecf'\nSystem info: host: 'selenium.questiondevelopment.com', ip: '43.35.51.12', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.0-18-amd64', java.version: '11.0.13'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:84)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:131)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:65)\n\tat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:143)\n\tat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:314)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:513)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:440)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:648)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:612)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:829)\n","exception.type": "org.openqa.selenium.SessionNotCreatedException","logger": "org.openqa.selenium.grid.node.config.DriverServiceSessionFactory","session.capabilities": "{\"browserName\": \"chrome\",\"platformName\": \"ANY\",\"platform\": \"ANY\"}\n"}}

12:10:51.092 WARN [SeleniumSpanExporter$1.lambda$export$0] - {"traceId": "a82ccdad343550c9da81ad23dd3c99fb","eventTime": 1658506251091847351,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "localhost:4444","http.method": "POST","http.request_content_length": "122","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession"}}

我的代码(正在工作)如下所示

代码语言:javascript
运行
复制
require __DIR__ . '/../vendor/autoload.php';

putenv('WEBDRIVER_CHROME_DRIVER=/var/www/chromedriver');

use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;

$serverUrl = 'http://localhost:4444/';

$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::chrome());

$driver->get('https://en.wikipedia.org/wiki/Selenium_(software)');

// Find search element by its id, write 'PHP' inside and submit
$driver->findElement(WebDriverBy::name('search')) // find search input element
->sendKeys('PHP') // fill the search box
->submit(); // submit the whole form

// Find element of 'History' item in menu by its css selector
$historyButton = $driver->findElement(
    WebDriverBy::cssSelector('#ca-history a')
);
// Read text of the element and print it to output
echo 'About to click to a button with text: ' . $historyButton->getText();

// Click the element to navigate to revision history page
$historyButton->click();

// Make sure to always call quit() at the end to terminate the browser session
$driver->quit();

我认为这与服务的运行方式有关。我也试着让Chromedriver在后台运行。我还试着通过

代码语言:javascript
运行
复制
$serverUrl = 'http://localhost:4444/wd/hub/';

但这并没有帮助。

编辑

我试着将Chrome升级到103,更新相应的Chromedriver并运行Selenium4.3.0,这一点都没有改变。我尝试了从不同用户运行Selenium的所有不同组合。我还将Chromedriver移到/usr/bin中,并尝试为它分配不同的权限。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73083281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档