As of 2015, the WebDriver specification became part of the W3C standard. The drivers are external, to make it more robust. We need to set the path to the driver executable in order to use the specific driver. (use `chmod +x [filename]` to make it executable on UNIX based systems) This section describes how to use Firefox.
Download the latest geckodriver from the following location: https://github.com/mozilla/geckodriver/releases
@Test public void useFireFoxDriver() { // Start browser System.setProperty("webdriver.gecko.driver", FileUtil.findFileOnPath("mac/geckodriver")); final FirefoxDriver driver = new FirefoxDriver(); // Open website driver.get("http://www.selenium-in-action.io"); // Close browser driver.quit(); }
Find file on path
public class FileUtil { public static String findFileOnPath(final String fileName) { if (new File(FileUtil.class.getClassLoader().getResource(fileName).getPath()).canExecute()) { return FileUtil.class.getClassLoader().getResource(fileName).getPath(); } else { return new File("src/main/resources/" + fileName).getAbsolutePath(); } } }