How To Setup a Selenium WebDriver Project in Eclipse ?
RSSS

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



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.

77 thoughts on “How To Setup a Selenium WebDriver Project in Eclipse ?

  1. James
    February 6, 2013 at 12:50 am

    Cool tutorial. This saved me a bunch of time figuring this out. Thanks for taking the time to create this. It was very helpful!

    1. February 6, 2013 at 1:05 am

      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

      1. vijay
        August 8, 2014 at 7:51 pm

        Very useful , God bless you.

    2. Triparie
      December 18, 2013 at 7:52 pm

      Very useful
      God bless you

    3. mounika
      January 6, 2014 at 9:13 am

      Thanks for that ,It is very Helpful to beginners :-)

  2. Nitish
    February 8, 2013 at 1:53 pm

    nice article !

    1. February 8, 2013 at 3:35 pm

      Thank you. Please press a +1 in Google.

  3. sateesh
    February 21, 2013 at 11:43 pm

    That saves me a lot of time … yesterday i have tried to install through maven it tooks too much time thanks…

    1. February 22, 2013 at 12:20 am

      Thanks sateesh. We will sort out the problems that you had with Maven in a short while.

  4. ss
    February 26, 2013 at 3:21 pm

    It’s really time saving for those who are going to start working with Selenium WebDriver :)

  5. microsense
    March 2, 2013 at 6:25 pm

    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?

  6. Manu
    March 4, 2013 at 4:17 pm

    I’m trying with python project instead of java project and struck in step 6. Please post for python as well.

    1. June 5, 2013 at 9:46 am

      you should look for topics which guide on how to create a python project in eclipse. You will have to integrate PyDev in eclipse.

  7. Ramana
    March 9, 2013 at 12:42 pm

    While i am running my script, initialization error is displayed. how to solve that issue. Please help me out to solve this issue.

    1. March 11, 2013 at 3:51 pm

      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.

      1. Ahmed Anwar
        March 28, 2013 at 3:19 am

        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′”

        1. March 28, 2013 at 10:24 am

          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.

  8. Amir
    April 7, 2013 at 3:24 pm

    How can I run to test this program

  9. April 21, 2013 at 4:15 am

    Thanks for the easy setup!! It works at first shot!!

  10. Pavan
    April 22, 2013 at 11:46 pm

    Thanks a lot it worked like a charm… can you please post how to automate a sample project in gradle?

    1. April 23, 2013 at 12:01 am

      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 :)

  11. Manjunath
    May 4, 2013 at 5:19 pm

    hi, i hear that maven is required to work with selenium..but here without using Maven…u did it…so why Maven is required?

    1. May 4, 2013 at 5:27 pm

      Maven is a build tool and using that is a best practice. I have posted another tutorial on how to setup with Maven.
      But, this is just without any build tools and a quick way to get started with Java and selenium.

  12. Guru
    May 10, 2013 at 9:14 am

    Please keep up this good work, its very informative

  13. vijaya
    May 30, 2013 at 7:31 pm

    Hi,
    Thanks a lot !! I was trying for 3 days n finally i was able to make it work with the help of your post.

  14. Ghanashyam
    June 2, 2013 at 1:38 pm

    Hi,

    Thanks a lot! These are the steps for new user. I am very happy for getting my problems.

    Thanks

  15. Suraj
    July 18, 2013 at 9:48 am

    Really good article . It helped me alot . But the images are not loading in my browser . My bad may be my company proxy settings is refusing the images in this site. But nice article really good one . :)

    1. July 18, 2013 at 2:27 pm

      May be. With which browser your tried ? No luck in trying with different browser ?

  16. July 21, 2013 at 3:58 pm

    Using IE or Firefox, images from your site, http://assertselenium.com/2012/10/28/how-to-setup-a-webdriver-project-in-eclipse/ , seem not to be displaying. URL for image(s) in this article resolve to “http://the4cast.in/wp-content/uploads/2012/10/18.png”. Hope they are viewable soon.

  17. salma
    August 16, 2013 at 9:40 am

    Hi ! Am new to web driver selenium and i have followed the above processes but when I run the script then am facing this “java.lang.unsupportedClassVersionError:Bad version number in .class file” issue please help me out and waiting for your reply…..PLEASE help me out.

  18. Sarbjit Singh
    August 25, 2013 at 12:10 pm

    Really nice tutorial. Saved my lot of time. Thanks buddy. Keep on posting such cool stuff.

  19. Lar
    August 30, 2013 at 2:07 pm

    A direct and straighforward example. I like it. Spent a while trying to figure out Maven too but this gets me started. Thanks alot!

  20. Arun Gee
    September 16, 2013 at 5:20 pm

    Thanks for this wonderful and simple article to configure the selenium in eclipse..

  21. Anonymous
    September 27, 2013 at 11:04 am

    Very much useful, thank for your valuable time

  22. L Davis
    October 1, 2013 at 4:16 pm

    Thanks for this post, very, very helpful. Worked the first time!

  23. Sankalp
    October 10, 2013 at 9:14 am

    can I follow the same procedure to use selenium it on iOS as well?

    1. October 10, 2013 at 12:47 pm

      you mean iOSDriver ? If Yes, Yes you can do the same with DesiredCapabilities parameters

  24. Bhavani
    October 15, 2013 at 6:02 pm

    Thanks a lot for the information…It helped me a lot. Could you please let me also know how to run the script here by taking any sample website?

  25. uday
    November 4, 2013 at 5:22 am

    This is Very good stuff for beginners like me..

    Can you please let me know how to create/maintain a folder structure( I mean separate test classes for all xpaths,css,etc) in Eclipse for TestNG, DataDrivenFramework in Webdriver.

  26. Ashish
    November 12, 2013 at 6:56 am

    Very good explanation. This is very very helpful .. Thanks a lot..

  27. Kavita Pandit
    November 26, 2013 at 4:17 am

    Thanks . Its very basic guide for selenium.
    very much helpful .

    1. October 20, 2014 at 7:50 am

      Nice Post! Very helpful to setup Selenium WebDriver Project in Eclipse.

  28. anitha
    December 11, 2013 at 12:07 pm

    when i am running selenium script in eclipse an error occured(Error: Could not find or load main class ).class file is not generating in bin folder.

  29. Umair
    December 24, 2013 at 3:31 pm

    That was a brilliant and simple tutorial!!!!!!!!
    Thanks Alot!
    Would be helpful if you were to place some tutorials up, where you show us how to Automate the first few screens of a website in the most simplest way.

    1. December 25, 2013 at 2:11 pm

      Sure, Would do that. Thanks for suggesting.

  30. dubliner
    December 28, 2013 at 3:23 am

    Thanks for that. Easy and simple way of going through the steps. Keep up the good work !

  31. kuntal
    January 28, 2014 at 12:29 pm

    Thank you so much

    Its a great website for self learners .. :)

  32. rakesh k.p
    February 17, 2014 at 6:10 pm

    Thank you so much for a very neat explanation

  33. Amit
    February 28, 2014 at 3:36 pm

    Thanks for the information, it is very good tutorial for beginners like me.

    Thanks
    Amit

  34. Amit
    February 28, 2014 at 3:38 pm

    It would be great if you could add a demo/sample for reference.

    Thanks
    Amit

  35. keerthi
    April 17, 2014 at 6:49 am

    good. i want a help import webdriver option is not displaying if i move my cursor overthere. wat to do .plz any 1 suggest

  36. Srikanth
    April 29, 2014 at 1:51 pm

    much helpful for the begginers thanks guys:)

  37. April 30, 2014 at 11:10 am

    It is very use full for us. Thank u so much for posting with screen shots

  38. Kousic
    May 1, 2014 at 10:29 pm

    Nice for new learners

  39. le
    May 5, 2014 at 8:52 am

    So coool, thanks a lot, it saves lots of my time

  40. Natarajan
    May 14, 2014 at 6:51 am

    Hi ,

    Thanks for sharing how to setup selenium using eclipse.

    Can i get some example programs and tutorial , Since i am new to Automation Testing.

    Share some basic selenium programs so i can try it out in eclipse.

    1. May 14, 2014 at 11:43 am

      That will be your task.. :)

  41. Saturn
    June 4, 2014 at 7:20 pm

    Thanks man, nice tutorial to setup selenium. I tried on Mac.

  42. user
    June 9, 2014 at 6:43 am

    thanks a lot

  43. June 11, 2014 at 3:42 am

    Thanks for posting how to install selenium web driver in eclipse. Its really helped me a lot. Thank Q so much…….:)

  44. Carl
    June 20, 2014 at 3:39 pm

    Great Tutorial! Set up in under 5 minutes

  45. Rakesh
    June 25, 2014 at 1:44 am

    you are really awsome thanks for the informative post. this helps greatly for the beginners.

  46. khurram
    June 28, 2014 at 7:56 pm

    its really helpful…..thanks

  47. Parth
    July 2, 2014 at 6:22 am

    Thanks!!
    it is very helpfull for bignners..

  48. prabhakar
    July 28, 2014 at 11:28 am

    The Fix you have suggested in step 17 and 18;I was unable to carry with because The option of importing the webdriver was not present when hovered the mouse over:

    {import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;}

    I have actually provided the import of webdriver and firefox in as :

    (import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver; )

    But Eclipse still fails in initiating the webdriver program.

    Please help in this regard asap.

    Let me know if I would have been able to provide a few more details from my End.

    Thanks in advance.

  49. Prashant
    July 30, 2014 at 8:08 am

    Thanks…
    It was quite helpful

  50. rautela
    August 5, 2014 at 5:44 am

    very good for the beginner, and way of demonstrate is also very easy.

  51. rav
    August 11, 2014 at 8:20 pm

    Very Usefull!!

    Thanks a bunch!

  52. Lalitha
    August 25, 2014 at 8:46 am

    Thanks a ton! It’s very helpful!

  53. vvd
    September 8, 2014 at 11:36 am

    Very usefull:)
    helped a’lot in setting up the selenium webdriver in eclipse.

  54. peiyao
    September 9, 2014 at 12:10 pm

    yes very useful :)

  55. Irshad
    September 9, 2014 at 12:36 pm

    Its really helpfull, thanks !!

  56. Parvathy
    September 16, 2014 at 1:36 pm

    Really Helpful. Thank you:)

  57. Hannah
    October 7, 2014 at 2:26 pm

    This is great. Easy to follow.
    Thank you!

  58. Meghana
    October 14, 2014 at 11:12 pm

    Awesome!! Thank you very much! It’s very useful and well explained in simple steps.

  59. Shri
    October 15, 2014 at 12:15 pm

    Thanks.It was really helpful.I just wanted to know whether this can be done with safari or particularly mac.

Leave a Reply

Your email address will not be published. Required fields are marked *