Home » Php » How do I get chrome working with selenium, using php webdriver?

How do I get chrome working with selenium, using php webdriver?

Posted by: admin July 12, 2020 Leave a comment

Questions:

Everything works fine with Firefox, but I can’t start chrome. I’m on linux, using php webdriver bindings.

require_once "/usr/local/src/selenium/php-webdriver-bindings-0.9.0/phpwebdriver/WebDriver.php";
putenv("PATH=".getenv("PATH").':'.'/usr/local/src/selenium/chrome_webdriver/'); //Prepare for chrome

$webdriver = new WebDriver("localhost", "4444");
//$webdriver->connect("chrome");
$webdriver->connect("chrome","",array(
    'webdriver.chrome.driver'=>'/usr/local/src/selenium/chrome_webdriver/chromedriver',
    ));

The error message I get is “The path to the chromedriver executable must be set by the webdriver.chrome.driver system property“. As you can see, I’ve tried setting that in the desiredCapabilities array, but that must be the wrong place. I can see in the selenium logs that my setting is getting through as this log line shows:

INFO - Executing: [new session: {javascriptEnabled=true, webdriver.chrome.driver=/usr/local/src/selenium/chrom..., browserName=chrome, nativeEvents=false, version=}] at URL: /session)

I start selenium with java -jar selenium-server-standalone-2.21.0.jar

I’m using Chromium v.18.

I created a shortcut /usr/bin/google-chrome that points to /usr/bin/chromium-browser

I can start chromedriver manually with no problems. It says:

port=9515
version=20.0.1133.0

Having that running, or not, does not make any difference to the error message selenium gives me.

UPDATE: Related question: selenium 2 chrome driver (answer there is for java, not php)

How to&Answers:

You can try passing the webdriver.chrome.driver property from commandline while starting the selenium server. Like this:

 java -Dwebdriver.chrome.driver = pathtochromedriver -jar selenium-server.jar

I am not sure about the reason why the other one is not working. You need to check whether its really setting the system property from code..

Answer:

Without any blanks it worked for me on WinXP32:

java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server.jar