问题
I have this code to set system properties:
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\driver\\chromedriver.exe");
Is it possible to store chromedriver executable within GitHub and use it in different projects? Something like this:
System.setProperty("webdriver.chrome.driver", "https://path_to_file/chromedriver.exe");
回答1:
The open source WebDriverManager may be the closest solution to what you are asking for.
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
This code will take care of downloading the right webdriver executable for your platform if needed and setting up the environment.
回答2:
I don't think it is possible because :
WebDriver using protocols to communicate with browser and It known asWebDriver JSON Wire Protocol
, which is actually a RESTful
web service using JSON
over HTTP
.
Here is a explanation of how it works : https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
So, using the driver as you want, you should run that driver.exe
on external source and you should communicate with it via selenium
.
There is only way to do what you want is improving and adding so much codes to selenium's source code.
回答3:
First of all hhttps://path_to_file/..
is an URL, conversationally termed a web address is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifier (URI). HTTP protocol enables/allows the client application (usually a web browser) to create HTTP requests containing the name of the web site it wants to contact for information exchange.
chromedriver executable location
In Troubleshooting - ChromeDriver it is mentioned that,
The path to the chromedriver executable must be set by the
webdriver.chrome.driver
system property and the chromedriver binary must be in the system path.
So, Selenium's client expects the WebDriver executable to be in PATH
i.e. the location of the WebDriver executable to be added within the OS native PATH
variable.
Conclusion
So it can be concluded that it won't be possible to store the WebDriver executable within GitHub and use it in different projects.
trivia
Even WebDriver executable e.g. ChromeDriver or GeckoDriver won't get initialized if they are accessed from a network path. You can find a detailed discussion in CreatePlatformSocket() returned an error: An invalid argument was supplied. (0x2726) when trying to access chromedriver through network path
来源:https://stackoverflow.com/questions/54867567/is-it-possible-to-set-chrome-webdriver-file-as-url