1. 程式人生 > >Selenium 3 -how to locate the chromedriver and geckodriver place?

Selenium 3 -how to locate the chromedriver and geckodriver place?

Maybe you met these exceptions sometimes:

1. Chrome Driver

The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

2. Firefox Driver

The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

After checking the selenium source code, I had found that the rule how they located these drivers in new selenium 3 API:

Invoke the WebDriver

org.openqa.selenium.chrome.ChromeDriver.ChromeDriver()

ChromeDriverService.createDefaultService();

new Builder().usingAnyFreePort().build();

org.openqa.selenium.remote.service.DriverService.Builder.build();

org.openqa.selenium.chrome.ChromeDriverService.Builder.findDefaultExecutable()

org.openqa.selenium.remote.service.DriverService.findExecutable(String, String, String, String)
String defaultPath = CommandLine.find(exeName);

String exePath = System.getProperty(exeProperty, defaultPath);

checkState(exePath != null,

"The path to the driver executable must be set by the %s system property;"

+ " for more information, see %s. "

+ "The latest version can be downloaded from %s",

exeProperty, exeDocs, exeDownload);

 

 

public String find(String named) {

File file = new File(named);

if (canExecute(file)) {

return named;

}

 

if (Platform.getCurrent().is(Platform.WINDOWS)) {

file = new File(named + ".exe");

if (canExecute(file)) {

return named + ".exe";

}

}

 

addPathFromEnvironment();

if (Platform.getCurrent().is(Platform.MAC)) {

addMacSpecificPath();

}

 

for (String pathSegment : pathSegmentBuilder.build()) {

for (String ending : ENDINGS) {

file = new File(pathSegment, named + ending);

if (canExecute(file)) {

return file.getAbsolutePath();

}

}

}

return null;

}

1. First option is place the driver file in your current WebDriver or RemoteWebDriver instance,for example:

If you current selenium server path is: /usr/selenium-server-version.jar ,then you must put the driver into this place

/usr and also MUST NOT change the driver’s name .

2. Add the driver into the PATH environment variable, in linux kernel system, you can put it into this place: /etc/paths.

For windows system you can put it in System environment or User environment Path variable .and also MUST NOT change the driver’s name.

3. Using programmatically java Code: System.setProperty(“”,””) here you can change the driver’s name.

Issues: Selenium Server is developed by Java, and using System.getEnv() to find the PATH variable ,so maybe the cache issue ,cannot located it correctly. When you changed the environment Path for chromedriver you need to restart the Java virtual machine again to make the changes affected.

相關推薦

Selenium 3 -how to locate the chromedriver and geckodriver place?

Maybe you met these exceptions sometimes: 1. Chrome Driver The path to the driver executable must be set by the webdriver.chrome.driver system property;

How to get the AQL Editor in place?

Sorry - just happened to see the documentation of the text toolkit - in one of the paragraphs they have mentioned the details about the ed

how to set the core dump file location(and name)?

1、如何長期開啟core dump功能?         編輯 /etc/profile,在末尾加上命令: ulimit -c unlimited >/dev/null 2>&1  &

Maven打包異常Unable to locate the Javac Compiler in:Please ensure you are using JDK 1.4 or above and

最近maven打包專案時出現以下異常: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.xxx: Comp

How to list the open file descriptors (and the files they refer to) in my current bash session

轉載 自https://unix.stackexchange.com/questions/333186/how-to-list-the-open-file-descriptors-and-the-files-they-refer-to-in-my-curren Yes, this will li

How to get the first date and last date of the previous month? (Java)

Calendar aCalendar = Calendar.getInstance(); // add -1 month to current month aCalendar.add(Calendar.MONTH, -1); // set DATE to 1, so first date of pr

From Bookstore to Smart Speaker Behemoth: How Amazon Conquered The Bookstore and is Using it to

While independent bookstores are experiencing a recent boom, chain bookstores like the kind Amazon Books resembles are clinging on for life. Borders, which

How to Watch the WIRED25 Festival and Summit

And of course, it wouldn't be a WIRED party without a robot petting zoo. The WIRED25 celebration kicks off today, Friday, October 12, followed by the WIRED

Ask HN: How to find the most favorited HN posts and comments?

I see people can favorite posts and comments and it's publically visibile too.So I was wondering like the HN leaderboard if there is a way to see the top X

How to visualise the Global Exporting Network using NetworkX and D3

How to visualise the Global Exporting Network using NetworkX and D3Data-Driven Documents (D3) is a JavaScript library for building powerful graphics to com

3 Ways to Enhance the Customer Experience Using AI and Machine Learning

Digital transformation is atop the list of every marketing leader's initiatives. While there's a lot of hype around AI and machine learning, there seems to

Tutorial: Generate BBox or Rectangle to locate the target obejct

mil 格式 trac documents rgb ims nts itl tro Tutorial: Generate BBox or Rectangle to locate the target obejct    1 clc;close all;clear

How To View the HTML Source in Google Chrome

inner eve spi together member mes mnt line split Whether you are new to the web industry or a seasoned veteran, viewing the HTML source o

question 002: dev c++ 當中如何調整字體大小?How to get the first program with C++? c++屬於什麽軟件?

space 什麽 pil get ctrl+鼠標 iostream 系統 using clu 方法:按住ctrl+鼠標滑輪滾動 c++屬於系統軟件還是應用軟件? 說哪個都不對,編譯之前屬於應用軟件,after compile ,it belongs to system so

How to Get the Length of File in C

code class clas body position pre -c set == How to get length of file in C //=== int fileLen(FILE *fp) { int nRet = -1; int nPosB

[Selenium+Java] How to Upload & Download a File using Selenium Webdriver

HR erb 14. ava inter pub was cape googl Original source: https://www.guru99.com/upload-download-file-selenium-webdriver.html Uploadin

[Selenium+Java] How to Take Screenshot in Selenium WebDriver

pack ID save nsh cfi box screen clas pen Original URL: https://www.guru99.com/take-screenshot-selenium-webdriver.html Screenshots are de

[Selenium+Java] How to use IntelliJ IDEA & Selenium Webdriver

sts quick public das nes www. button margin state Original URL: https://www.guru99.com/intellij-selenium-webdriver.html How to use Int

How to program BMW KOMBI and NBTwith ENET E sys cable ICOM A2

cau was member obd 6.4 ren lease better entry This is how to set up Router or DHCP server for BMW KOMBI and NBT programming with Enet e

How to use Kata Containers and CRI (containerd plugin) with Kubernetes

bsp use k8s doc ner blob ber uber net https://github.com/kata-containers/documentation/blob/master/how-to/how-to-use-k8s-with-cri-contain