Launch Firefox Browser using Selenium:
- ‘WebDriver‘ is an interface and we are building a reference variable ‘driver‘ using the ‘FirefoxDriver()‘ class, a quick webdriver.
- WebDrivers for different browsers: FirefoxDriver() for Firefox browser, ChromeDriver() for Google Chrome, SafariDriver() for Safari Browser, InternetExplorerDriver for Internet Explorer etc.
- Webdriver is an Interface and FirefoxDriver() is a class which has implemented Webdriver Interface.
- Interface, there is a set of variables and methods without any body (no implementation, only method name and signature). We can not instantiate objects from the interface.
- WebDriver is an interface which contains all the unimplemented common methods, which can be used for any browser e.g. getTitle(), getCurrentUrl(), get(), findElement() etc.
Download Geckodriver.exe:
- Geckodriver.exe Download from GeckoDriver Github release page Make sure to download the correct driver file based on your platform and OS version.
- Set the system property for “webdriver.gecko.driver” with Geckodriver.exe path – System.setProperty (“webdriver.gecko.driver”, “geckodriver.exe path”);
What is GeckoDriver?
- A proxy for W3C WebDriver-compatible clients to interact with Gecko-based browsers.
- Geckodriver provides the HTTP API described by the WebDriver protocol, so that Gecko browsers, such as Firefox.
- Mozilla runs on Gecko browser engine.
- As part of the Mozilla Browser, the Gecko Browser Engine was developed by the Mozilla Foundation.
- It can help applications render web pages, just like other browsers, Chrome, Internet Explorer and Edge Mozilla Foundation have decided to introduce the Marionette driver to control Firefox browser.
- This is an open source browser engine, which can be used by any person. However, the Gecko browser engine is not limited to the Mozilla browser.
Specify System Properties with Path:
1 2 3 4 5 | // Set System Property for Gecko with geckodriver.exe path System.setProperty("webdriver.gecko.driver","path of geckodriver.exe"); // We create a reference variable for the WebDriver interface and instantiate using the Firefoxdriver class. WebDriver driver = new FirefoxDriver(); |
Example of Launch Firefox Browser using geckodriver:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Importing Packages import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class GeckoDriver { public static void main(String[] args) { // Set geckodriver path System.setProperty("webdriver.gecko.driver","D:\\geckodriver.exe"); // Instantiating objects and variables WebDriver driver = new FirefoxDriver(); // Enter URL after launching browser driver.get("https://www.stqatools.com"); // Print Pagetitle System.out.println("Title is :- "+driver.getTitle()); // Close Firefox Browser driver instance driver.close(); } } |
Output:
1 | Title is :- Software Testing Quality Automation Tutorials |
Importing packages:
- org.openqa.selenium. * : Includes the required WebDriver class to instantiate a new browser loaded with a specific driver.
- org.openqa.selenium.firefox.FirefoxDriver : The FirefoxDriver() class is required to install Firefox-specific drivers via the WebDriver class immediately to the browser.
firefox geckodriver selenium java and firefox geckodriver selenium java or firefox geckodriver selenium java