Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
678 views
in Technique[技术] by (71.8m points)

maven - selenium 2 chrome driver

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add WebDriverManager to your project:

<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
    <version>5.0.1</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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...