In this article, we discuss how to open new Firefox geckodriver window using selenium 3. Firefox 47 and onwards Mozilla is now packaging the driver separately. The current webdriver is known as marionette. And from here onward in order to run the Selenium programs you need to make use of the geckodriver. So we cover how to setup geckodriver, eclipse project and make use of the new selenium 3 webdriver.
If you like to read instructions then keep reading. If you like to watch the video then check below to learn how to setup Geckodriver and use it with Selenium 3 Webdriver.
Selenium 3 WebDriver for Java
Go to the Selenium HQ website. And download the Selenium Server and Java WebDriver Client.
Download Firefox Geckodriver
You can check the geckodrivers github page.
From here you can download the driver in zip file. After downloading the zip file you need to extract this into folder.
This path to the folder where you can downloaded geckodriver.exe needs to be in system path.
To add the application in path, you need to follow the steps below. You can skip this step if you want but it helps to add this driver into the system variables.
Set Environment Variables for Windows (Optional)
1. Go to Windows Button.
2. Go to Computer Link.
3. Right click on the menu option of computer link.
4. Choose Properties.
5. When the Systems window opens up check the left hand sidebar.
6. Choose Advanced System settings.
7. This opens “System properties” dialog box.
8. Click on “Environment Variables” button.
9. Copy the path to the “geckodriver.exe”
12. Now find path in “System Variable”.
13. Paste the copied geckodriver into it.
14. Save the settings by clicking on Ok button.
Setup Eclipse Project
Now we need to setup the eclipse project. Follow the instructions below to setup eclipse for selenium 3 Java webdriver.
1. Open Eclipse IDE.
2. Go to File > New > Java Project.
3. Name your project, project folder and choose the Java version as 1.8.
4. Click next.
5. In this dialog box choose the build tab.
6. Find the directory where you have downloaded the selenium server.
7. Add the selenium server to the path.
8. Add the Selenium Java webdriver binding to the path.
9. Click finish to create the project.
10. After your project is created you have to create a class.
11. Go to File > New > Class. Name it “Demo”
12. Add the following code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;public class Demo {
public static void main(String[] args) {
System.setProperty(“webdriver.gecko.driver”,”\\path to\\geckodriver.exe”);WebDriver driver = new FirefoxDriver();
driver.get(“http://www.google.com”);
System.out.println(“Website Name : “+driver.getTitle());
driver.quit();}
}
Now you need to run the program. You’ll find the Firefox browser instance open. And on the console you’d find the website name shown as google. This is just a small example. And you can now run more complex programs depending on your needs. I hope this article helps you work with the new Geckodriver with the new Selenium 3 webdriver for Java. If you have any specific question then feel free to ask here. Do share the above video and the article with your friends on social media. 🙂