Setting Up a Eclipse Project With Selenium
March 08, 2016
- Open Eclipse
- Click on File > New > Java Project > Enter a project name e.g. SeleniumProj
- Click Next
- Click on Libraries tab and click on Add External JARs
- Add the JARs from the WebDriver client library folder and the JARs from the libs subdirectory. Click Finish
- Right click on the project folder and select New > Class
- Enter a Package and Class Name and then click Finish
- Enter you first Selenium WebDriver code to navigate to a web page in Firefox
[java]
package net.brav3.webdriver.chapter1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class NavigateToAUrl {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get(”https://developer.mozilla.org”);
}
}
[/java]
Note: If you get an error that Firefox crashed, make sure to check the Selenium issues on Github. There may already be a solution either involving updating to the latest Firefox, Selenium WebDriver, or the Marionette WebDriver from Mozilla.