-1

I am trying to run facebook/php-webdriver package, but I am stuck in this stage.

It works fine in my localhost, but in my Ubuntu server, after some wait I get this error

Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"firefox"}} Operation timed out after 30001 milliseconds with 0 bytes received

This is what my code looks like

 $browser_type = 'chrome';
      $host = 'http://localhost:4444/wd/hub'; // this is the default
        $capabilities = array(\Facebook\WebDriver\Remote\WebDriverCapabilityType::BROWSER_NAME => $browser_type);
                   $driver = \Facebook\WebDriver\Remote\RemoteWebDriver::create($host, $capabilities);
        $driver->get($setconnection);
        $driver->get($setavail);
        $cookie = $driver->manage()->getCookies();
        $driver->close();

        $cookie = reset($cookie);

        $cookievalue = $cookie['value'];

Basically, I am trying to get cookievalue from this request, anyone, have some solution, please !!

Cowgirl
  • 1,454
  • 5
  • 19
  • 40

2 Answers2

1

This usually means a problem with the Selenium server session. Your server waits for Firefox to open, but it's failing to do so. You should be using a headless browser (a browser specifically made for automation)

In the localhost (your pc), there is a display environment, your computer screen, the Firefox will just launch and close as it normally would.

But in the server you might not have configured a display environment, the best solution is to specify a headless firefox clause in facebook php web driver - https://github.com/facebook/php-webdriver/issues/506

$capabilities = \Facebook\WebDriver\Remote\DesiredCapabilities::firefox();
$capabilities->setCapability(
    'moz:firefoxOptions',
   ['args' => ['-headless']]
);
Dhiraj
  • 2,687
  • 2
  • 10
  • 34
0

The error told you the script fail to access this url http://localhost:4444/wd/hub, even your script put in same machine, but it can't access itself: localhost

Such issue usually caused by proxy/iptables/firewall/hostname setting in linux machine, please check those settings.

A possible duplication: Set up Selenium on CentOS7

For Windows machine, there is not much place can control network traffic by OS itself, so far i know set environment variable for proxy can do that, and proxy setting in browser.

But for linux machine, there are many place can set to contorl network traffic, like I said above. And for different Linux OS, those setting occurs in different file/place, or has different cmd to do that.

Additional, nowdays VM/docker, for those two stuff the newwork setting more complex.

yong
  • 13,357
  • 1
  • 16
  • 27