Automation Testing

Selenium WebDriver Quick Guide Using Java with Eclipse

By Test Guild
  • Share:
Join the Guild for FREE

In a previous post I showed how to get started using Selenium 2.0 WebDriver with Visual Studio, C# and IE. Since then I've received a few questions on how to do the same with Selenium Web Driver and Eclipse. Rather than answer each one individual, I thought it would be better to frame my replay in the form of a quick post.

Turns out that not only does Internet explorer not play nice with Selenium and Visual Studio but it also has odd behavior in Eclipse as well. Hopefully this post will help you get started on your learning Selenium in Eclipse journey.

Download Selenium Java Client Drivers

  • The first step is to download the Selenium Client Drivers Java DLLs from Selenium's web site: http://seleniumhq.org/download/


  • You'll also want to download the Internet Explorer Driver Server from the same location.


  • Once you've downloaded the required Selenium files, extract the zips to a local drive on your computer.

Configure Eclipse to work with Eclipse

  • Launch Eclipse and create a ‘New Java Project'. Name it SeleniumIE:


  • Right click on the SeleniumIE project and select New>Class
  • In the New Java Class dialog enter the Name: SeleniumIEDriver and make sure to click on the ‘public static void main(String[]args). Click Finish


  • In Eclipse click on the Propject>Properties menu
  • In the Properties for SeleniumIE dialog click on the ‘Java Build Path' and the ‘Libraries' tab


  • Navigate to the directory where you unzipped the Selenium Java Driver to
  • Add all the jars from the selenium-x.xx.x directory and the libs directory:



  • One all the jars are added click OK on the Properties for SeleniumIE dialog

Time to write Selenium Java Code!

  • Now it's time to write some code. For this example I'm going to use a simple test web application that I created:


  • At the top of your SeleniumIEDriver class add the following namespaces
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import junit.framework.Assert;
    import org.openqa.selenium.*;
    import org.openqa.selenium.ie.*;
    import org.openqa.selenium.WebDriver;
    
  • Next under the main section of your SeleniumDriver class create an instance of the InternetExplorereDriver
    WebDriver ieDriver = new InternetExplorerDriver();
    
  • After we have an instance to the IE web driver we can navigate to a web page using it's get method
    ieDriver.get("https://testguild.com/HpSupport.html");
    
  • Verify the correct page loaded using an assertion with the driver's getTitle method
    Assert.assertEquals("Joe's HP Support Matrix Tool for QTP, LoadRunner, Service Test and Quality Center",driver.getTitle());
    
  • Select a value from the ‘Select your tool & version' dropdown using the findElements and sendkeys methods using the By ID to locate the tools element. (FYI: If you are going to be scripting against IE you'll want to install the Internet Explorer Developer Toolbar. (Those familiar with QTP are aware that this is similar QTP's spy tool).Check out my post Selenium 2.0 WebDriver with Visual Studio, C#, & IE Getting Started for more info.)
    WebElement myTools2 = ieDriver.findElement(By.id("tools"));myTools.sendKeys("QTP10");
    
  • When ending a script it's a good practice to kill all the WebDriver instances:
    driver.quit();
    
  • The final code should look like this:


Common Selenium Errors

These are two most common errors/warnings that I see when using Selenium in Eclipse with Internet Explorer:

  1. The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://code.google.com/p/selenium/downloads/list WARNING: This method of starting the IE driver is deprecated and will be removed in selenium 2.26. Please download the IEDriverServer.exe from http://code.google.com/p/selenium/downloads/list and ensure that it is in your PATH.
  • If you receive this error you most likely forgot to add the IEDriverServer.exe to you PATH environment variable or misspelled it. To fix right click on you're my Computer icon and in the ‘System Properties' dialog select the Advanced tab than click on the Environment Variables button.


For example my InternetExplorerDriver is located on my D drive under a Download directory. All I did was add that to the end of the existing values in my PATH variable:


  1. org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO: Retrying request.
  • From what I can tell this is just a warning that can be ignored. This is the best explanation on stackoverflow that I could find – “This is a warning message. The native code (C++) component of the IE driver includes an HTTP server, since the driver uses the JSON Wire Protocol for its communications. That HTTP server takes a small amount of time to start and be ready to receive HTTP requests. However, the RemoteWebDriver's HTTP client (remember that InternetExplorerDriver is a subclass of RemoteWebDriver) cannot know exactly when that server is available, so this causes a race condition. The HTTP client must poll the server until it receives a valid response. When you're seeing this warning, it's only telling you that the internal HTTP server hasn't completed its initialization, and the HTTP client has lost the race. It should be harmless, and you should be able to safely ignore it.” – Jim Evans

What Internet Browser Versions has Selenium been tested against

As of now (Nov 2012) the IEDriver has been tested against IE 6, 7, 8 and 9. For updated IEDriver information check out the Selenium InternetExplorerDriver Wiki

Good Luck, and happy Selenium scripting!

Optimized Bio with Podcast Longevityfor

Maximum Credibility & SEO

A bearded man with blue glasses and a black-and-white jacket smiles at a microphone in a studio setting.

About Joe Colantonio

Joe Colantonio is the founder of TestGuild, an industry-leading platform for automation testing and software testing tools. With over 25 years of hands-on experience, he has worked with top enterprise companies, helped develop early test automation tools and frameworks, and runs the largest online automation testing conference, Automation Guild.

Joe is also the author of Automation Awesomeness: 260 Actionable Affirmations To Improve Your QA & Automation Testing Skills and the host of the TestGuild podcast, which he has released weekly since 2014, making it the longest-running podcast dedicated to automation testing. Over the years, he has interviewed top thought leaders in DevOps, AI-driven test automation, and software quality, shaping the conversation in the industry.

With a reach of over 400,000 across his YouTube channel, LinkedIn, email list, and other social channels, Joe’s insights impact thousands of testers and engineers worldwide.

He has worked with some of the top companies in software testing and automation, including Tricentis, Keysight, Applitools, and BrowserStack, as sponsors and partners, helping them connect with the right audience in the automation testing space.

Follow him on LinkedIn or check out more at TestGuild.com.

  1. Hi Joe,

    Excellent info. Just one issue though. Does the PATH variable need to be one of the System Variables on the Environmental Variables page? I am unable to edit these so created a user variable called PATH and added the location. However, this doesn’t seem to work.

  2. Hi
    Im not able to open ie9 in windows 7 using selenium script.. how to write the script ? If u know plz tell me.

  3. Hi Joe,

    Thanks for this step by step info . I am facing an error “cannot be resolved ” in the last 2 lines of the code- driver and my tools.
    Could you please guide me in this

  4. Hi Joe,
    I work with QTP. I want to learn Selenium WebDriver. Can u suggest a book to start off with Selenium WebDriver, which contains One-stop all contents regarding Selenium WebDriver/Grid/…etc. Thanks 4 ur help !

  5. Thanks a lot for this tutorial Joe, great help.

    If people have issues with the IE Driver setup (WTF # 1), here is a work-around:

    File file = new File(“<full_path_to_ie_driver");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

    Add these two lines to your code before you instantiate the InternetExplorerDriver.

  6. Joe,
    Great Job!!

    Any chance you could update with instructions for Firefox?
    As TruClient mainly uses Firefox, wanted to see if transaction times are similar.

    Andrew

  7. Dear Joe,

    I am new to this Selenium WebDriver. currently I am trying to launch IE with following code.

    import java.io.File;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.ie.InternetExplorerDriver;

    public class myclass {
    public static void main(String[] args) {
    final String sUrl = “http://www.google.co.in/”;
    File file = new File(“C:/Users/245610/IEDriverServer.exe”);
    System.setProperty(“webdriver.ie.driver”, file.getAbsolutePath());
    WebDriver oWebDriver = new InternetExplorerDriver();
    oWebDriver.get(sUrl);
    WebElement oSearchInputElem = oWebDriver.findElement(By.name(“q”)); // Use name locator to identify the search input field.
    // oSearchInputElem.sendKeys(null);
    WebElement oGoogleSearchBtn = oWebDriver.findElement(By.xpath(“//input[@name=’btnG’]”));
    oGoogleSearchBtn.click();

    try {
    Thread.sleep(5000);
    } catch(InterruptedException ex) {
    System.out.println(ex.getMessage());
    }
    oWebDriver.close();
    }
    }

    I am getting following error in console

    Exception in thread “main” java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V
    at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59)
    at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:48)
    at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:100)
    at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:81)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.(DriverCommandExecutor.java:46)
    at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:192)
    at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:184)
    at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:155)
    at mypackage.myclass.main(myclass.java:16)

    could you help me what exactly it means and how to solve.

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Solving the Top 6 Mobile Automation Challenges Fast (DevAssure Guide)

Posted on 02/27/2025

Are you tired of struggling with the mobile test automation setups? Does managing ...

Top Software Testing Conferences (2025 Guide)

Posted on 01/19/2025

Why a list of top software testing conferences? Many testers ask me what ...

Top 8 Automation Testing Trends Shaping 2025

Posted on 01/11/2025

As we enter 2025, here are some automation testing trends I think will ...

AG '25 Online Event: Defeat Flaky Tests, Future-Proof Your Skills, & Grow Your Network in 2025 - Learn More >>

⭐⭐⭐⭐⭐ “A must-attend virtual event for all testing professionals.” — George Ukkuru (Head of Quality Eng.)