Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium 2 chrome driver

Tags:

So I have read all the docs on adding chromedriver to my path and followed all of them. I am on a Mac with selenium2, maven, eclipse, and all the latest drivers:

Error:
The path to the chromedriver executable must be set by the webdriver.chrome.driver system property;

I put chromedriver in my Applications folder and my path looks like:

echo $PATH  
/Users/tcerrato/selenium/BS_Sel_Project/auto_helper/test_scripts:/usr/local/apache-maven-2.2.1//bin:/Users/oracle/oracle/product/10.2.0/db_1/bin:/opt/local/bin:/opt/local/sbin:/Applications:

What am I missing? I cannot run with chrome driver at all. Any help would be great I'm trying random stuff now.

Here is my pom section on selenium:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium</artifactId>
    <version>2.0rc2</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>2.6.0</version>
</dependency>
like image 473
ducati1212 Avatar asked Sep 16 '11 21:09

ducati1212


2 Answers

I am not sure about Maven but this how I set the property webdriver.chrome.driver

System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
like image 40
nilesh Avatar answered Oct 01 '22 01:10

nilesh


Add WebDriverManager to your project:

<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
    <version>5.1.0</version>
</dependency>

This library downloads the latest version of the WebDriver binary you need and export the proper Java system variable (webdriver.chrome.driver, webdriver.gecko.driver, webdriver.opera.driver, webdriver.edge.driver, webdriver.ie.driver), simply using one of the following sentences respectively:

WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.iedriver().setup();

More info on https://bonigarcia.dev/webdrivermanager/

like image 114
Boni García Avatar answered Oct 01 '22 01:10

Boni García