In previous article we have seen about What is Selenium Webdriver? In this article we are concentrating on implementation of the WebDriver, we will see how to selenium webdriver download and configure the Selenium Webdriver with Eclipse & run your first Selenium WebDriver script.
Selenium WebDriver installation is divided in to simple steps to get & learn how to Install & configure WebDriver to kick of your automation testing. Also we will run your first automation script using WebDriver.
Step 1) Download & Install Java on your Computer
Before start working with the Learn Selenium WebDriver, we will need the first download Java Development Kit (JDK).
Here you can download Java Development Kit (JDK).
Step 2) Install Eclipse on your computer
Eclipse is open source software development environment written in Java. It supports supports multiple languages. In this tutorial we will using Eclipse to write the code in Java & execute your first test script.
Here you can download “Eclipse IDE for Java Developers”
Make sure that you are downloading correct version of Eclipse based on the Windows 32 or 64 bit version.
Once you select the windows version based on your requirement, you should be able to download a “eclipse-java-juno-SR2-win32-x86_64.zip” ZIP file.
Once you successfully download the ZIP file, extract the ZIP file in your PC.
For Eclipse, you do not need any installation; just double click on “eclipse.exe” file in the extracted ZIP folder.
Step 3) Download Selenium Java Client Driver
Selenium client driver is available in the different languages like Java, C#, Ruby, Python etc. But in this article we are concentrating on Java language.
Here you can download “Selenium Java Client Driver”
Once you click on Download link for Java client then you should be able to download a “selenium-java-2.31.0.zip” ZIP file.
Once you successfully download the ZIP file, extract the ZIP file in your PC in the directory “C:\selenium- java-2.31.0”. You will see JARs files in extracted folder which would be imported in to Eclipse before running our first Selenium WebDriver script.
Step 4) Configure Eclipse with Selenium WebDriver
In Step 2 we have installed Eclipse, just Launch the “eclipse.exe” file from the extracted Eclipse folder.
Once you open the “eclipse.exe” file then it will ask you to select the workspace, here you can select the path where you want to save Eclipse project.
First step is to create a Java Project:
- Go to File menu > New > Java Project.
- Enter Project Name as “Selenium_webdriver_project”
- Click on Finish button.
Second step is to create a Class under Java project:
- Under newly created project “Selenium_webdriver_project” you will see the “src“ folder & right click on the “src” folder & create the new class as “Webdriver_class”.
Once you created the class you will see the Eclipse screen like this.
- Right click on “Selenium_webdriver_project” & select Properties option.
- Select “Java Build Path” option in the left side of the Properties dialog box.
- Click on Libraries tab
- Click on “Add External JARs..” button.
- Select the extracted Selenium Java Client Driver folder downloaded in Step3 & add all JAR files present in the inside & outside of the “libs” folder. Once you select these JAR files then your properties folder will look like as below.
- Click on OK in the Properties dialog box to import.
Step 5) Run your first Selenium WebDriver script.
Once you complete the Step 1 to Step 4 then you are ready to execute your first WebDriver script. You can just copy paste the code written below & click on Run button to execute your first script. Code below which is written to opens the new Firefox browser window & open the Google page in it. It also read the Title of the page & close the browser window.
//Run yout First Selenium WebDriver script by copy paste below code after executing above five simple steps. import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Webdriver_class { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://google.com"); System.out.println(driver.getTitle()); driver.close(); } }Conclusion:
In the next module we will see some more Selenium Webdriver tutorials & its features. Working with the WebDriver is really interesting, you will love these modules as it has got so many information on WebDriver & Selenium which help you a lot while doing the interviews & while doing automation testing using. Stay tuned for more updates
or
If you are not regular reader of our website then highly recommend you to sign up for our free email newsletter!! Sign up just providing your email address below:
Happy Testing!!!
- What is Selenium Webdriver? – Selenium Training Series
- Selenium Training Series – Getting Started with Selenium IDE
- How to create Selenium WebDriver Test using Selenium IDE? – Selenium Tutorial
- Why Selenium Server not required by Selenium WebDriver?
- Learn JUnit annotations used for your Selenium WebDriver automation
- How to use JUnit Annotations in Selenium WebDriver Automation Script
- Getting Started With Installation Of Selenium WebDriver – Learn Selenium
- How To Access Links & Tables Using Selenium Webdriver?
- Complete Guide on Implicit and Explicit Wait in Selenium
- Start Selenium WebDriver Test Script on your own – Selenium Tutorial
34 thoughts on “How to run your first Selenium WebDriver script – Selenium WebDriver Tutorial”
good job. very helpful
Am really thankful for providing detailed info.. as i joined small s/w company.. and am being so confused, what to do first, and how to test…
Thank u once again
Great Work!!! very useful …
The indetails practical information about webdriver is helpful for fresher
Hi, Nice artical. I just started to read about testing tools and i started to read manual testing. Please give an advice do i need to start on manual or Automation.
Hi I am looking for the next article as you mentioned in the conclusion (where you will be providing information about Selenium Web driver tutorials & its features) , have you published if so please post the URL for the same . Thanks in advance !!
Good Going… Nice one. Keep Going. Doing really Great Job.
heyyyyy,
Thanks alot for giving this informative website.I’ve been getting information clearly
superbbbb
Excellent one….All articles are awesome:)
Link for next tutorial???
It’s wonderful post.Clears basic idea to start webdriver…waiting for your next post.
I followed above steps.
I am using firefox 24.0.
I used selenium-2.37.0 jars.
But I am getting this error.
Please help me to avoid this error.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7056 after 45000 ms. Firefox console output:
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\prasathm\AppData\Local\Temp\anonymous5105779955122335603webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
*** LOG addons.xpi: Installed distribution add-on {635abd67-4fe9-1b23-4f01-e679fa7484c1}
im getting
Exception in thread “main” java.lang.Error: Unresolved compilation problems:
The method get(String) is undefined for the type Webdriver_class
Syntax error, insert “;” to complete Statement
The method getTitle() is undefined for the type Webdriver_class
The method close() is undefined for the type Webdriver_class
at Webdriver_class.main(Webdriver_class.java:8)
Hi prasath,
check you firefox version that has been updated by latest version so you need add selenium 38 jar file in your project build path by deleting existing.
thanks,
sydeesh
when i run the programm as the java application i get a option to select java application . which option i have to select there. ??
Hi
i am going to download selenium web driver but when I click download link this error appears:
403. That’s an error.
Request not allowed from your country That’s all we know
i,e I dont accecc googlecode.com
Dont you know another way or link I can download it
thanks alot
Superrrrrrrrrrrrrrrrrrrrrrrrrr.. no words !
I have followed the above steps properly but I am getting the error-NoClassDefFoundError. Please help me to resolve this issue.
Exception in thread “main” java.lang.NoClassDefFoundError: com/google/common/base/Function
at com.tcs.webdriver.Webdriver.main(Webdriver.java:12)
Really very useful for fresheres
Nice article… its really useful to me and my team members.
Thank you so much. I done it in one time. Superb!!!!
Thank you so much.
it is not working on my machine
shows following error
Exception in thread “main” java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:60)
at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:56)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at Selenium.main(Selenium.java:11)
Caused by: org.openqa.selenium.WebDriverException: ‘webdriver.firefox.bin’ property set, but unable to locate the requested binary: C:\Firefox Setup.exe
Build info: version: ‘2.52.0’, revision: ‘4c2593c’, time: ‘2016-02-11 19:03:33’
System info: host: ‘User-8-PC’, ip: ‘192.168.0.40’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_60’
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.locateFirefoxBinaryFromSystemProperty(Executable.java:145)
at org.openqa.selenium.firefox.internal.Executable.(Executable.java:45)
… 4 more
Hi All,
I have followed the above steps to configure Selenium Webdriver and I am unable to continue and facing the below mentioned error message. Can someone help me regarding this issue.
Exception in thread “main” java.lang.NoClassDefFoundError: com/google/common/base/Function
at Webdriver_class.main(Webdriver_class.java:8)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
… 1 more
Great!!!… its very useful
Hi,
I am new to testing so this may be a very silly question. However, I need clarification. When I run this test, I get the following error: Where have I gone wrong? Please help.
Exception in thread “main” java.lang.NoClassDefFoundError: com/google/common/base/Function
at Webdriver_class.main(Webdriver_class.java:8)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 1 more
appears – BeanShell 2.0b4 – by Pat Niemeyer (pat@pat.net)
bsh %
Please solve
Kindly update the screenshot and relevant content for selenium web driver beta version (current version)
I am not getting any error but the program is also not working. It just opens Mozilla home page and stops.
Thanks , its very helpful to me and my friends.
Nice work, it was very useful for everyone , and I was learn quickly what is selenium, thanks for wonderful work !!!
When you right-click on the Selenium_webdriver_project, and select properties, there are 2 nodes: ModulePath and Classpath. I assumed it was ModulePath, is that correct?
Update. I forgot to mention that I was under the Library tab
When you right-click on the Selenium_webdriver_project, and select properties, there are 2 nodes under Libraries tab: ModulePath and Classpath. I assumed it was ModulePath, is that correct?