3

I'm seeking to add options to an instance of Facebook/php-webdriver.

This works to get the initial options:

$options = \Facebook\WebDriver\Remote\DesiredCapabilities::chrome();

Now I'd like to add additional options:

$options->setCapability("enablePassThrough", FALSE);
$options->setCapability("no-sandbox", TRUE);

I'm getting the error:

Call to undefined function setCapability()

I've tried a few approaches, but haven't yet found out how to do it.

What is the correct way to add options to an instance of Facebook/php-webdriver?

danronmoon
  • 3,814
  • 5
  • 34
  • 56
VikR
  • 4,818
  • 8
  • 51
  • 96

3 Answers3

5

setCapability()

setCapability() method configures the WebDriver instance with the capabilities through an instance of DesiredCapabilities() as follows:

public function testShouldProvideAccessToCapabilitiesUsingSettersAndGetters()
{
    $capabilities = new DesiredCapabilities();
    // generic capability setter
    $capabilities->setCapability('custom', 1337);
    // specific setters
    $capabilities->setBrowserName(WebDriverBrowserType::CHROME);
    $capabilities->setPlatform(WebDriverPlatform::LINUX);
    $capabilities->setVersion(333);
    $this->assertSame(1337, $capabilities->getCapability('custom'));
    $this->assertSame(WebDriverBrowserType::CHROME, $capabilities->getBrowserName());
    $this->assertSame(WebDriverPlatform::LINUX, $capabilities->getPlatform());
    $this->assertSame(333, $capabilities->getVersion());
}

--no-sandbox

-no-sandbox argument can be added through instance of ChromeOptions() and further can be added to the instance of DesiredCapabilities() as follows:

$options = new ChromeOptions();
$options->addArguments(array('--no-sandbox'));
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);

enablePassThrough

enablePassThrough mode was introduced for the first time in Selenium Client v3.5.0 . enablePassThrough allowed a connection from your test's RemoteWebDriver, through the Grid Hub, to a Grid Node, and down to a DriverService and then to the browser to use the same WebDriver protocol (the Json Wire Protocol or the W3C one) end to end without translation.

enablePassThrough mode could have been disabled by starting the standalone server or Grid node with the argument -enablePassThrough false

With the release and availability of Selenium Client v3.9.0 all HTTP communication was switched to OkHttp. Though you can still change the version back to the Apache HttpClient by setting the webdriver.http.factory system property to apache.

Simultanously support for the passthrough mode for the server was dropped.

Here you can find a detailed discussion on enablePassThrough not available for selenium server 3.9.1

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Could you provide additional detail? On `$options = new ChromeOptions();` I am getting: `Message: Class 'ChromeOptions' not found`. If I do: `$options = \Facebook\WebDriver\Remote\DesiredCapabilities::chrome(); $options->addArguments(array('--no-sandbox'));` I get the message, `Call to undefined method Facebook\WebDriver\Remote\DesiredCapabilities::addArguments()`. – VikR Oct 24 '18 at 17:39
  • @VikR Honestly I am not that regular with facebook-php-driver but I have provided the hyperlink for each of the topics for your reference. Let me know if you are looking for more documentation. – undetected Selenium Oct 24 '18 at 17:56
  • I did see the link for the `SetCapability` docs yesterday. It has the code you note, but on my system throws the errors I am seeing. So I still need an answer regarding how to do this. At the same time, I have upvoted your response. Thanks for this good info! – VikR Oct 24 '18 at 18:02
  • @VikR Can you add your observations within the main question so I can lookout exactly to what you are looking for? – undetected Selenium Oct 24 '18 at 18:20
  • 1
    Thanks @DebanjanB for asking and for the great info you previously posted! I found the correct syntax and have posted it below. – VikR Oct 24 '18 at 21:25
0

This syntax works on my system:

    $options = new \Facebook\WebDriver\Chrome\ChromeOptions();
    $options->addArguments(array('--no-sandbox'));
    $capabilities = \Facebook\WebDriver\Remote\DesiredCapabilities::chrome();
    $capabilities->setCapability(\Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY, $options);
    $seleniumDriver = \Facebook\WebDriver\Remote\RemoteWebDriver::create(
        $host,
        $capabilities,
        5000
    );
VikR
  • 4,818
  • 8
  • 51
  • 96
  • I don't see any significant change in your code other than duplicating the absolute path of the _Class_ i.e. **`new ChromeOptions()`** being changed to `new \Facebook\WebDriver\Chrome\ChromeOptions()` and so on. – undetected Selenium Oct 25 '18 at 10:35
-2
$options = new ChromeOptions();
$options->addArguments(array('--no-sandbox'));
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
Rodrigo Carmona
  • 605
  • 1
  • 5
  • 6
  • 2
    This answer is *exactly* the same as a section of [this other answer](https://stackoverflow.com/a/52967085/) to this question. [From Review](https://stackoverflow.com/review/low-quality-posts/27757716) – Ian Campbell Dec 03 '20 at 03:49