Launch Firefox using Selenium

Viewed 184

I am Trying to lunch Firefox and do a simple search on Google but i am only able to launch the Firefox. what should be edit in the code to run it smooth?I am Using Firefox Quantum 57 which runs using maven dependencies.

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirefoxLaunch
{
    @Test
    public static void main(String [] args) {
        WebDriver driver;
        driver = new FirefoxDriver();
        driver.get("https://google.com");
        WebElement element =driver.findElement(By.name("q"));
        element.sendKeys("FirefoxDriver Search Function");
        driver.quit();
    }
}
1 Answers

While working with:

  • Selenium v3.x clients
  • Firefox Quantum v70.x

You need to download the binary from this link and save it in your system and then provide the absolute path of GeckoDriver binary through System.setProperty() line as follows :

System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
Related