skip to Main Content

I’m trying to get a Debian VM with Selenium + PHP running again. It was working a few months ago.

I tried running Selenium (in an ssh connection) as the Nginx user and as root. Both produce the same error

java -jar ./selenium-server-4.1.1.jar standalone
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:u002fu002flocalhost: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 u002fusru002fbinu002fgoogle-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 u002fusru002fbinu002fgoogle-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: unknownntat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)ntat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:84)ntat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62)ntat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:131)ntat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:65)ntat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:143)ntat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:314)ntat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:513)ntat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:440)ntat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:648)ntat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:612)ntat java.baseu002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)ntat java.baseu002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)ntat java.baseu002fjava.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"}}

My code (which was working) is as follows

require __DIR__ . '/../vendor/autoload.php';

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

use FacebookWebDriverRemoteRemoteWebDriver;
use FacebookWebDriverRemoteDesiredCapabilities;
use FacebookWebDriverWebDriverBy;

$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();

I assume it’s something to do with how the services are running. I tried making Chromedriver run in the background as well. I also tried connecting via

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

But that did not help.

Edit

I tried updating Chrome to 103, updating the corresponding Chromedriver and running Selenium 4.3.0 and that changed nothing at all. I tried all different combinations of running Selenium from different users. I also moved Chromedriver into /usr/bin and tried assigning it different permissions.

2

Answers


  1. Chosen as BEST ANSWER

    It turned out I was not creatinging the web driver with the proper arguments. This code fixed my issue :

    $chromeOptions = new ChromeOptions();
    $chromeOptions->addArguments(['--no-sandbox']);
    $chromeOptions->addArguments(['--headless']);
    $chromeOptions->addArguments(['--disable-extensions']);
    $chromeOptions->addArguments(['--disable-gpu']);
    
    $capabilities = DesiredCapabilities::chrome();
    $capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions);
    

    https://github.com/php-webdriver/php-webdriver/wiki/Chrome

    How do you run Selenium headless in PHP?

    PHP Fatal error: Uncaught Error: Class 'FacebookWebDriverChromeOptions' not found


  2. This error message…

    Build 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
    

    …implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. and presumably the ChromeDriver version can’t be detected and is unknown


    Solution

    Ensure that:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search