Creating a Simple Selenium – Java project in Eclipse
This post will help the selenium users-Beginners to setup the selenium project and execute a simple WebDriver script
Refer to my latest blog post on setting up Firefox in Selenium 3.0
Steps To Create a Selenium Project in Eclipse
Step 1: Download Eclipse
Step 2: Creating a New Java Project in Eclipse IDE
Step 3: Enter a Project Name E.g:SampleDemo
Step 4: Creating a New Package
Right Click on the New Java Project created → New→ Package
Step 5: Type In a New Package Name E.g:com.selenium.example
Step 6: Creating a New Java Class file.
Right Click on the Newly created Package → New → Class
Step 7:Type In a Name for your Java Class file,
click on the check box for “public static void main (String args[])”
Click on Finish
Step 8: The Java class file is created and ready for Java Scripting.
Now, We need to add the Selenium Library files to our project
Step 9: Download the selenium server from the seleniumhq.org website.
Step 10: Click on Downloads Tab and then click on the link as highlighted in the screenshot
Step 11: Save the jar file in a specific Location E.g C:/Selenium
Step 12: Configuring Build Path.
Right Click on the package → Build Path → Configure Build Path
Step 13: Click on Libraries tab → Add External Jar’s
Step 14: The jar files should be loaded from the C:/Selenium folder (or where you have saved the downloaded Jar file from Seleniumhq website) to our Eclipse Workspace and should look as in the screenshot
Step 15:We can also verify by expanding the Referenced Libraries in the Project Explorer that, whether the Jar file is added properly
Step 16: Now, our Eclipse is ready for Selenium Scripting 🙂
Web Driver object initialization as WebDriver driver=new FirefoxDriver();
As in the below Screenshot
You may see errors, but that’s not a problem here is how we resolve it.
Step 17: Mouse Hover near the WebDriver error line you will see an Auto suggest Option, you will find Import WebDriver.
Click on Import WebDriver –Now the error will be vanished.
Step 18: Now Mouse Hover near the Firefox Driver, and you will get an autosuggest option.
Click on the Import FirefoxDriver option the suggested list
You can also eliminate the steps 15,16,17 by manually adding the below Import statements
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
And, that’s it we are done with Selenium Project setup in Eclipse.
Hope this helps!!!
Please comment if you have any questions/comments, I will try to reply at the earliest.
Cool tutorial. This saved me a bunch of time figuring this out. Thanks for taking the time to create this. It was very helpful!
I am glad it helps you out. Please dont forget to share the page to everyone and also like the page in FB at http://assertselenium.com
Thanks
nice article !
Thank you. Please press a +1 in Google.
That saves me a lot of time … yesterday i have tried to install through maven it tooks too much time thanks…
Thanks sateesh. We will sort out the problems that you had with Maven in a short while.
It’s really time saving for those who are going to start working with Selenium WebDriver 🙂
What is the difference between using selenium-server-standalone-2.31.0.jar compared to selenium-java-2.31.0.jar as external referenced jar for a Selenium webdriver project?
I’m trying with python project instead of java project and struck in step 6. Please post for python as well.
While i am running my script, initialization error is displayed. how to solve that issue. Please help me out to solve this issue.
Share the stack trace of the error that you faced here, that will help me to get to know what error it it. Mostly I will be online in the selenium irc channel, that will be the best place to guide you.
Anwar: I am having this error message “Exception in thread “main” org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8
Build info: version: ‘2.31.0’, revision: ‘1bd294d’, time: ‘2013-02-27 20:53:56′”
It because, Selenium doesnt know where is the Firefox binary to kick off your tests from Win 8. I suggest you to please google on this error Or try to check in the Selenium Users group these kind of errors are all provided with solution.
How can I run to test this program
Thanks for the easy setup!! It works at first shot!!
Thanks a lot it worked like a charm… can you please post how to automate a sample project in gradle?
Glad it helped you.
Gradle is also a build automation tool like Maven. The approach is same but I understand the dependencies and plugins mapping will vary.
Try it on your own, let me know where you get trouble.
we will work together 🙂
Thanks a lot!!… Got the best flow.. 🙂
Thanks, Great job (Y)
How I can import jar files. There are 2 jar files outside the folder and inside too.
Hi,
I am getting following error message when i configure Selenium standalone server in Eclipse IDE.
Unable to access jarfile selenium-server-standalone-2.48.2.jar
How can i solve this…
Hi,
Is there any way by which we can import the selenium libraries only once and we can use them in every Java project without importing the selenium jars every time for every Java project.
Thanks Manoj for the steps provided to setup selenium.
thanks alot. helped a lot while mapping selenium web driver to eclipse.
Good article. Very useful
It’s a very good article . It helped me a lot in adding selenium into eclipse.
Thanks to the author.
hi,
i am not getting any import statement under options.
only create class,fix project, rename file is coming .
how can i resolve this .
i am using eclipse mars and selenium version 2.52.
I just followed the above same steps , even i am getting error
WebDriver driver = new FirefoxDriver();
It is showing error in the driver .can you please help me as soon as possible.
Thanks Brother!
Thanks it ‘s a very useful article thank alot
The errors appears like this when am trying to open flipkart in firefox
Exception in thread “main” java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:37)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:95)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:277)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:247)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:242)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:238)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:127)
at FlipKartTest.main(FlipKartTest.java:7)
Refer to my latest blog post on using Firefox in Selenium3.0
i had done all the step to run my script above but the system is throwing a error message”Exception in thread “main” org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:1129″ somehow help me guys
Hi,
While creating a java script for web driver I am not able to import the driver script into the program.
The actual issue is import file for ex: (import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver) is not found in lib.
True! things have changed a lot since I wrote the blog post, and I haven’t got time to update the post.
Refer to a blog post named using firefox in selenium 3.0
Can anyone tell me how to download selenium and selenium webdriver in ubuntu.
This article was very helpful!! if we have an article for simple program with steps it would be very helpful for beginners.!!..:-)
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
Hi sir, where these 2 steps are include in java program, can u plz guide me, i can’t understand the proper way to include the same
Hi , is your issue resolved? If yes then please guide me through. 🙂