Facebook Webdriver ChromeOptions Not Found Issue – Resolved

JTS

While working on a few crawling projects we were looking to figure out how the change the USER-AGENT string on a chrome instance.

All of the guides said it was simple to add user agent options.

$options = new ChromeOptions();
$options->addArguments(array(
    '--user-agent=' . $userAgent
));
 
$caps = DesiredCapabilities::chrome();
$caps->setCapability(ChromeOptions::CAPABILITY, $options);
 
$driver = RemoteWebDriver::create($host, $caps);

Seemed easy enough, but when we added it to the example from Facebooks’ github page ( Here), we kept getting the error “Fatal error: Uncaught Error: Class ‘Facebook\WebDriver\ChromeOptions’ not found”.

After trying everything in the book, we realized that we didn’t include that actual library that is required. Duh!

When we added the following lines at the top, it worked like a charm.

namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
require_once('vendor/autoload.php');

About the author

During his twenty-five professional years, Mr. Silva has had experience in nearly every facet of the Information Technology industry. Ranging from advanced data mining / data visualization systems to running multi-state small business IT infrastructures, Mr. Silva has always provided precise and cost-effective strategies to meet any client’s needs. With his tremendous work ethic and “Can-Do” attitude, Mr. Silva has always met every challenge head-on and with intelligent determination. Mr. Silva is also a certified NAUI Advanced/Nitrox Diver, hoping to get a few more wrecks under his belt in the Atlantic.