可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:
org.seleniumhq.seleniumselenium2.0rc2pomorg.seleniumhq.seleniumselenium-chrome-driver2.5.0org.seleniumhq.seleniumselenium-firefox-driver2.6.0
回答1:
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");
回答2:
Add this dependency to your project:
io.github.bonigarciawebdrivermanager2.1.0
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
, phantomjs.binary.path
, webdriver.edge.driver
, webdriver.ie.driver
), simply using one of the following sentences respectively:
WebDriverManager.chromedriver().setup(); WebDriverManager.firefoxdriver().setup(); WebDriverManager.operadriver().setup(); WebDriverManager.phantomjs().setup(); WebDriverManager.edgedriver().setup(); WebDriverManager.iedriver().setup();
More info on https://github.com/bonigarcia/webdrivermanager
回答3:
Setting the webdriver.chrome.driver
system property via maven can be done by the following (and tested working):
Add systemPropertyVariables
configuration to the maven-surefire-plugin
in your pom.xml
. This is (typically) because surefire
is the caller for tests and where system properties will be set.
maven-surefire-plugin2.7.1${webdriver.chrome}
Now define ${webdriver.chrome}
somewhere. A good start is a
section in your pom.xml
/home/gede/bin/chromedriver
Potentially this could be done better via the use of
like in Simon Martinelli's example
回答4:
You could have a go at using the driver binary downloader maven plugin to download the driver binaries for you (https://github.com/Ardesco/selenium-standalone-server-plugin):
com.lazerycode.seleniumdriver-binary-downloader-maven-plugin1.0.7${project.basedir}/src/test/resources/selenium_standalone_binaries${project.basedir}/src/test/resources/selenium_standalone_zipsselenium
This will download the binaries and set a maven property that you can use in your surefire/failsafe configuration like this:
org.apache.maven.pluginsmaven-failsafe-plugin2.7.2${phantomjs.binary.path}${webdriver.chrome.driver}${webdriver.ie.driver}${webdriver.opera.driver}**/*WebDriver.javaintegration-testverify
When you instantiate a new driver object the system property pointing to the driver binary location will now be set and it will just work.
回答5:
So in the pom you have to set it like this
org.seleniumhq.seleniumselenium-chrome-driver2.34.0
This is a java code to run the chrome using selenium
System.setProperty("webdriver.chrome.driver","C:/chromedriver.exe"); WebDriver myD = new ChromeDriver();
In order for you to run Chrome you need to download the chrome driver from here. https://code.google.com/p/chromedriver/downloads/list
Once you have done that then you have to set it in environment variable. Read this https://code.google.com/p/selenium/wiki/ChromeDriver
Thanks,
Mediha
回答6:
System.setproperty("webdriver.chrome.driver","your file path here with chromedriver.exe"); webDriver driver=new chromeDriver(); driver.get("http://google.com");
回答7:
Try this:
System.setProperty("webdriver.chrome.driver","/location to/chromedriver folder"); WebDriver driver = new ChromeDriver(); driver.get("your.app");
回答8:
Just add WebDriverManager in your maven pom and it works without manual setup if you have your browser setup in default config.
回答9:
It works for me without setting webdriver.chrome.driver
property. Just by adding chromedriver to PATH
> echo $PATH /usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin > > which chromedriver /usr/local/bin/chromedriver
If you use Homebrew, installing chromedriver along with adding to PATH can be done as simple as this:
brew install chromedriver
Useful links:
https://sites.google.com/a/chromium.org/chromedriver/
http://brewformulas.org/Chromedriver
回答10:
Pom.xml code and Selenium code below: com.HelloWorldt0.0.1-SNAPSHOTjarthttp://maven.apache.orgUTF-8/home/gede/bin/chromedriversrc/main/java/resourcestruemaven-surefire-plugin2.7.1${webdriver.chrome} org.apache.maven.pluginsmaven-surefire-plugin2.20testng.xmljunitjunit3.8.1testorg.seleniumhq.seleniumselenium-chrome-driver3.8.1org.seleniumhq.seleniumselenium-java3.4.0org.testngtestng6.8testorg.seleniumhq.seleniumselenium-chrome-driver3.8.1io.github.bonigarciawebdrivermanager2.1.0com.relevantcodesextentreports2.41.2org.apache.logging.log4jlog4j-api2.8.2org.apache.logging.log4jlog4j-core2.8.2 Selenuim Code public class App { static String currentDir = System.getProperty("user.dir"); static WebDriver driver; @BeforeClass public static void setupClass() { ChromeDriverManager.getInstance().setup(); driver= new ChromeDriver(); driver.get("https://www.google.com/"); } @Test public void test() { System.out.println( "Hello World!" ); } }