Close

September 11, 2017

Facebook Webdriver ChromeOptions Not Found Issue – Resolved

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');

Fatal error: Uncaught Error: [] operator not supported for strings in /home/silvatec/public_html/wp-content/themes/layerswp/core/helpers/post.php:62 Stack trace: #0 /home/silvatec/public_html/wp-content/themes/layerswp/partials/content-single.php(81): layers_post_meta(4019) #1 /home/silvatec/public_html/wp-includes/template.php(690): require('/home/silvatec/...') #2 /home/silvatec/public_html/wp-includes/template.php(647): load_template('/home/silvatec/...', false) #3 /home/silvatec/public_html/wp-includes/general-template.php(167): locate_template(Array, true, false) #4 /home/silvatec/public_html/wp-content/themes/layerswp/single.php(20): get_template_part('partials/conten...', 'single') #5 /home/silvatec/public_html/wp-includes/template-loader.php(74): include('/home/silvatec/...') #6 /home/silvatec/public_html/wp-blog-header.php(19): require_once('/home/silvatec/...') #7 /home/silvatec/public_html/index.php(17): require('/home/silvatec/...') #8 {main} thrown in /home/silvatec/public_html/wp-content/themes/layerswp/core/helpers/post.php on line 62