Introduction to Firefox Gecko Driver for Selenium
Firefox gecko driver is used to perform the automation testing in Firefox browser. For selenium 3 you need to download the gecko driver to run the scripts in Firefox browser. Mozilla has released the gecko driver to support the latest version of selenium.
You can download the latest version of Firefox gecko driver from the following
Link:
https://github.com/mozilla/geckodriver/releases
After downloading Firefox gecko driver, extract it in the current project directory. You can also set the path of this folder in the System’s PATH variable.
After extracting Firefox gecko driver in the correct location you need to add the following lines of code in your script to run your script in the Firefox browser:
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); /* you can write you code here*/ driver.quit();
Let us understand how your script runs in Firefox Browser:
In the below example we are navigating to a link and get the source of the page and in that page source we are checking that the string which we are looking for is present or not
import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; public class Automation{ //Open the Firefox browser System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); String lookingFor = “Iphone X” // Navigate to webpage driver.get("https://www.apple.com/in/"); //Get the page source of current open page String pageSource = driver.getPageSource(); // comparing String pageSouce with string lookingFor if ( pageSouce.equals(lookingFor) ) { System.out.println("The String which we are looking for is present"); } else { System.out.println("The String is not present"); } // closing the Firefox Driver driver.quit(); }