Why do we need to set the system property for Chrome and IE, and not for Firefox

For Chrome,

public class Chrome { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://www.google.com"); } } 

for firefox,

 public class Firefox { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); } } 

Why do we need to specify system.setProperty for Chrome and IE?

+7
source share
3 answers

I also had the same question, but after digging, I found

WebDriver uses a native browser approach. Selenium offers a built-in driver for Firefox, but not for other browsers. All drivers (Chrome driver, IE driver, etc.) Built on the basis of a special JS engine used by each browser.

Selenium WebDriver works very well with Mozilla Firefox because it has a built-in driver server. But the same does not apply to Internet Explorer and Google Chrome. Firefox is the most traditional browser, so Selenium WebDriver does not require installing any additional utilities before launching the browser. The Selenium package automatically references the default location for firefox.exe, so the user does not need to set any other property.

If you ever get the error message "the path to the executable file of the driver must be set by the web driver, that is, the property of the system property of the driver" or in a similar way equivalent to Chrome, this means that you need to install the driver servers in the browser. A driver server manages calls between browsers and the Selenium Wire protocol.

InternetExplorerDriver is a standalone server that implements the wired WebDrivers protocol.

Similarly, Google Chrome does not have an embedded server, so you will need a Chrome driver server to transfer your Selenium code to the browser. You can download the Chrome driver server.

Founded from here .

+6
source

The implementation of FirefoxDriver, ChromeDriver, InternetExplorerDriver is different, so the way to instantiate the object is also different.

The Firefox driver controls the Firefox browser using the Firefox plugin. The used Firefox profile is removed from what is installed on the computer to enable only Selenium WebDriver.xpi

InternetExplorerDriver is a standalone server that implements the wired WebDrivers protocol.

ChromeDriver is supported / supported by the Chromium iteslf project. WebDriver works with Chrome through the chromedriver binary file (located on the download page of chrome projects). You need to have both a chrome recorder and a version of the Chrome browser. chromedriver needs to be placed somewhere on your system path so that WebDriver will automatically detect it. The Chrome browser itself was detected by a chrome rib along the default installation path.

See selenium documentation for more details.

+1
source

The answer is simple: each browser has its own implementation of WebDriver and is not supported by the Selenium project. Therefore, for selenium to interact with a specific browser driver, we need to specify the full path to the driver.

Why is there no need for firefox to specify the path to the driver? In Selenium 2.0, Selenium RC is still present and supports Firefox. Starting with Selenium 3.0 and beyond there is no official support for any drivers for specific browsers. Therefore, we need to specify the path to the driver through System.setproperty for all browsers.

0
source

Source: https://habr.com/ru/post/1242591/


All Articles