Create And Run First Webdriver Script With Eclipse

Run First Webdriver Script
You need to install webdriver with eclipse to run your script in webdriver. Before running your first selenium webdriver test, you also need to download geckodriver to run your test in mozilla firefox browser. steps to download geckodriver are as below.

Download geckodriver


  • Go to geckodriver download page.
  • On geckodriver download page, you will find latest version release of geckodriver.
  • Download geckodriver win64 version if you are working with windows 64 bit system.as shown in below image.
download geckodriver
  • You will get zip file of geckodriver.
  • Extract it. You will geckodriver.exe from extracted folder.
  • Copy and paste it at D:\Selenium Files (Selenium Files folder in D: drive).

After downloading geckodriver exe and installation of webdriver software testing tool, You need to write a java code in eclipse for your test case of software web application. Let me give you one simple example of creating simple webdriver script for software web application. First of all you need to create the package called "Testing_Pack" under your project and then create new class file 'mytestclass.java' under that package. Now copy-paste bellow given code In your 'mytestclass.java' file.

package Testing_Pack;

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

public class mytestclass {

 public static void main(String[] args) {
  //set geckodriver path.
  System.setProperty("webdriver.gecko.driver","D:\\Selenium Files\\geckodriver.exe");
  //initialize firefox driver object to open firefox browser.
    WebDriver driver = new FirefoxDriver();
    //open URL in browser.
    driver.get("http://only-testing-blog.blogspot.com");
    String i = driver.getCurrentUrl();
    System.out.println(i);
    driver.close();
   }
}


Now you are ready to run your script from Run menu as shown bellow.


Script Explanation
Above script will 
  • open Firefox browser. 
  • Then driver.get syntax will open 'http://only-testing-blog.blogspot.com/' software application in firefox browser.
  • Then driver.getCurrentUrl() will get the current page URL and it will be stored in variable 'i'. You can do same thing using "storeLocation" command in selenium IDE
  • And at last, it will print value of variable in console as shown bellow.

So this is the simple webdriver script example. You can create it for your own software web application too by replacing URL in above script. We will learn more scripts in detail in my upcoming posts.

VIEW MORE TUTORIALS ON WEBDRIVER

74 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Thank you very much !
    This is very well written and very helpful !

    ReplyDelete
  3. Hi,

    I am completely new to selenium.While trying to run the , I am getting the below information in console.

    Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at mytestpack.mytestclass.main(mytestclass.java:10)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    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

    Please help.

    ReplyDelete
    Replies
    1. Hi RamKumar,

      Even I am seeing the same error, if you have found fix let me also know.

      Thanks in Advance

      Delete
    2. Try by adding selenium-server-standalone jar file as external jar file and try again. Please comment back if your problem get resolved.

      Delete
    3. Hi, I'm new to Selenium. I have tried the above program and also added selenium-server-standalone-2.410 jar in external jar library but I'm still getting the below error.

      java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver (Unsupported major.minor version 50.0)
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      at java.security.SecureClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.access$100(Unknown Source)
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      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)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      Exception in thread "main"

      Pls. let me know if anything is missed out.

      Thanks,


      Delete
    4. QUESTION:_ " I am getting the below information in console. Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function"
      ANSWER: Copy and paste this line of code System.setProperty("webdriver.gecko.driver", "C:\\\\EclipseMaka2017\\GECKO\\geckodriver.exe");
      right after
      "{"
      but before
      "WebDriver driver = new FirefoxDriver();" :

      Delete
  4. thanks that was very helpfull for a newbie like me

    ReplyDelete
  5. Very helpful post.
    But I am getting below message after running
    Could not find the main class: mytestpack.Selenium2Example. Program will exit

    ReplyDelete
  6. Thanks you! Very helpful!

    ReplyDelete
  7. thank you ! very nice Example and very useful

    ReplyDelete
  8. Thanks you! Very nice Example and very helpful!

    ReplyDelete
  9. Thanks
    but I had to add selenium-server-standalone-2.37.0.jar to external library to get
    import org.openqa.selenium.firefox.FirefoxDriver;

    ReplyDelete
  10. Very Helpful.
    I have a question thought. I have used selenium ide for a test case but i had to move to selenium webdriver in order to catch some errors/exceptions.
    I have also used flow control but in exported file from ide i get this: // //ERROR: Caught exception [unknown command [gotoIf]]
    How can i export ide test case as it is without having to write the case again?

    ReplyDelete
  11. Hi Guys,

    After writing the code and if i run , i get below error

    Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:"C:\Program Files\HP\Unified Functional Testing\bin\java_shared\classes";"C:\Program Files\HP\Unified Functional Testing\bin\java_shared\classes\jasmine.jar"


    Does anybody has any idea what going on in this..


    Thanks & Regards,
    Raghavendra J

    ReplyDelete
  12. Hi!
    The blog was really useful and easy to understand but i get an error after the webdriver is launched.

    "org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms."

    Could you explain whats the reason??

    Thanks in advance,
    Vijay.R

    ReplyDelete
  13. Hi!
    The post was really usefull and easy to understand. I followed the above steps, but i received the following exception in the console.
    "org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms."

    Could you explain how to rectify

    ReplyDelete
  14. The post was really usefull and easy to understand. I followed the above steps, but i received the following exception in the console.

    ReplyDelete
  15. its really helpful to me
    thanks

    ReplyDelete
  16. Oi eu gostaria muito de receber o arquivo de código de amostra conforme indicado no seu texto. E parabéns estou fazendo o tutorial webdriver farei o IDE, e estou gostando muito.

    ReplyDelete
  17. It would be helpful to all if the blog admin could clear the doubts on errors posted here in this section. Anyone who comes across such errors will know what to do.

    ReplyDelete
  18. Thank you...its very helpfull

    ReplyDelete
  19. Thanks for your post. It's very helpful

    ReplyDelete
  20. Thanks for your post. It's very helpful.

    ReplyDelete
  21. Thanks for your post. It's very helpful,
    But i am getting this error Please help me ...

    org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
    *** LOG addons.manager: Application has been upgraded

    ReplyDelete
    Replies
    1. Update latest firefox version if you have older one and download latest version of jar files of selenium webdriver from http://docs.seleniumhq.org/download/ and relace them with older jar files in eclipse.

      Hope this will help you. Please reply back if it works for you..

      Delete
  22. Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:106)
    at mytestpack.mytestclass.main(mytestclass.java:8)


    i am facing this issue can you pleae help on this please

    ReplyDelete
  23. Hi ,

    I am new to selenium , I am getting the below error when I executed my first script

    A pop up with "could not find the main class"


    java.lang.UnsupportedClassVersionError: Bad version number in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    Exception in thread "main"

    The program is as below

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

    public class wiki_project
    {
    public static void main(String[] args)
    {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://google.com");
    System.out.println(driver.getTitle());
    driver.close();
    }
    }


    versions :
    Java : 1.5
    FireFox:29.0.1

    ReplyDelete
    Replies
    1. Try to search solution online. I think this error Is related to configuration of eclipse.. bellow given link will help you.
      http://stackoverflow.com/questions/2466828/java-lang-unsupportedclassversionerror-bad-version-number-in-class-file

      Delete
  24. My code is as below


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

    public class wiki_project
    {
    public static void main(String[] args)
    {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://google.com");
    System.out.println(driver.getTitle());
    driver.close();
    }
    }

    and verision are

    JAVA : 1.5
    Firefox:29.0.1

    ReplyDelete
  25. Thanks, very useful tutorial!

    ReplyDelete
  26. Thanks so much for your easy-to-follow tutorial! Great work!

    ReplyDelete
  27. Thanks for much for the easy-to-follow tutorial. Great work!!

    ReplyDelete
  28. Thanks for much for the easy-to-follow tutorial. Great work!!

    ReplyDelete
  29. This is great. Thank you.

    ReplyDelete
  30. This tutorial is awesome! Thanks so much!

    ReplyDelete
  31. It was really helpful tutorial...
    plz send me sample code example.
    Thanls!

    ReplyDelete
  32. I have copied your code and I am getting following error message..not sure what is the problem

    Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA
    Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
    System info: host: 'VIEWSU-5', ip: '172.16.10.32', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_20'
    Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.firefox.internal.Executable.(Executable.java:72)
    at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:59)
    at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:55)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:95)
    at TestPack1.Test1Class.main(Test1Class.java:11)

    ReplyDelete
    Replies
    1. Looks like webdriver Is not able to find your firefox binary path. add bellow given line before WebDriver driver = new FirefoxDriver(); syntax to set binary path. It will work.

      System.setProperty("webdriver.firefox.bin","C:/Program Files/Mozilla Firefox/firefox.exe");

      Delete
    2. yes exactly, even I get the same error and when i add "System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");" then the code is executed successfully.

      Please let me know why webdriver is not able to find the chrome binary path?

      Delete
  33. Very nice tutorial to start up.. Thanks alot for sharing it :)

    ReplyDelete
  34. Hi , I am new to Selenium and when I tried the abpuve code with SL 2.44 and FF33.1.1 , I am getting the below error


    Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
    4c6-7e08-4474-a285-3208198ce6fd} visible
    1422264902527 DeferredSave.extensions.json DEBUG Save changes
    1422264902528 DeferredSave.extensions.json DEBUG Save changes
    1422264902528 addons.xpi DEBUG New add-on {D19CA586-DD6C-4a0a-96F8-14644F340D60} installed in winreg-app-global
    1422264902535 addons.xpi-utils DEBUG Make addon winreg-app-global:{D19CA586-DD6C-4a0a-96F8-14644F340D60} visible
    1422264902535 DeferredSave.extensions.json DEBUG Save changes
    1422264902535 DeferredSave.extensions.json DEBUG Save changes

    ReplyDelete
  35. Hi I am new to Selenium, Tried the above vode with Selenium 2.44 and Ff 31.4.0.But getting below error.

    Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
    s (x86)\Mozilla Firefox\_MMC\de-DE@dictionaries.addons.mozilla.org
    1424274455735 addons.xpi DEBUG Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\_MMC\de-DE@dictionaries.addons.mozilla.org
    1424274455737 addons.xpi DEBUG Calling bootstrap method startup on de-DE@dictionaries.addons.mozilla.org version 2.0.4
    1424274455739 addons.xpi DEBUG Registering manifest for C:\Program Files (x86)\Mozilla Firefox\_MMC\en-gb@flyingtophat.co.uk
    1424274455739 addons.xpi DEBUG Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\_MMC\en-gb@flyingtophat.co.uk

    ReplyDelete
  36. when i execute the above code the follwoing error is displayed but in the same code when i add "" line then the error is removed and am able to execute the code successfully. Can you let me know why so?

    error message before adding that line:
    Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:117)
    at SeleniumDemoWD.JTWebdriverTest.main(JTWebdriverTest.java:10)

    ReplyDelete
  37. sorry i missed to mention the line that I added:

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");

    ReplyDelete
  38. Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at mytestpack.mytestclass.main(mytestclass.java:8)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    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
    igot this Error.Plz.Help me

    ReplyDelete
  39. i am getting this error
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at Testing_pack.mytestclass.main(mytestclass.java:8)

    my code is
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at Testing_pack.mytestclass.main(mytestclass.java:8)



    please help me as soon as possible

    ReplyDelete
  40. Hi,

    I'm new to Selenium. I have tried the above program.

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:96)
    at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:70)
    at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:58)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:97)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:117)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:218)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:211)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
    at TestjUnit.mytestclass.main(mytestclass.java:9)
    Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
    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)
    ... 11 more

    Please let me know if I have anything.

    Thanks

    ReplyDelete
  41. Very useful !

    Thank you so much

    ReplyDelete
  42. I have been googling for two days for tutorial on Selenium. All ended up having some errors. But your tutorial is clearly explained step by step and worked in the first try itself. Thank you so much for this awesome tutorial.

    ReplyDelete
  43. Hello,

    Hi , I am new to Selenium and when I have SL 2.53.0 and FF 45.0.2 , I am getting the error :

    java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : Unsupported major.minor version 51.0

    Thanks

    dormont

    ReplyDelete
  44. Hi , I am new to Selenium and when I tried the above code with SL 2.53.0 and FF45.0.2 , I am getting the below error

    java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : Unsupported major.minor version 51.0

    Thanks

    Michel

    ReplyDelete
  45. It's OK with JDK 1.8.0_77, SL 2.53.0 and FF 45.0.2 !
    Thanks
    Very clear and useful

    Michel

    ReplyDelete
  46. Hi,

    When i am using the above code. Following error is coming.



    org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
    ue,"userDisabled":false,"appDisabled":false,"descriptor":"C:\\Program Files\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1461765373659,"updateDate":1461765373659,"applyBackgroundUpdates":1,"skinnable":true,"size":22006,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"46.0","maxVersion":"46.0"}],"targetPlatforms":[],"seen":true}
    1461833567120 addons.xpi DEBUG getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
    1461833567121 DeferredSave.extensions.json DEBUG Save changes
    1461833567121 addons.xpi DEBUG Updating database with changes to installed add-ons
    1461833567121 addons.xpi-utils DEBUG Updating add-on states
    1461833567122 addons.xpi-utils DEBUG Writing add-ons list
    1461833567124 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
    1461833567124 addons.xpi DEBUG Calling bootstrap method startup on e10srollout@mozilla.org version 1.0
    1461833567124 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
    1461833567124 addons.xpi DEBUG Calling bootstrap method startup on firefox@getpocket.com version 1.0
    1461833567125 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\loop@mozilla.org.xpi
    1461833567126 addons.xpi DEBUG Calling bootstrap method startup on loop@mozilla.org version 1.2.6
    1461833567140 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
    1461833567140 addons.xpi DEBUG Calling bootstrap method startup on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 8.0.0.9103
    1461833567254 addons.manager DEBUG Registering shutdown blocker for XPIProvider
    1461833567255 addons.manager DEBUG Provider finished startup: XPIProvider
    1461833567255 addons.manager DEBUG Starting provider: LightweightThemeManager

    ReplyDelete
  47. Thanks for your amazing tutorials. But After running the code above, I am getting following error.

    Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
    System info: host: 'DESKTOP-EOKA2KD', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
    Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:218)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:211)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
    at test.test.main(test.java:12)
    Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
    at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
    at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
    at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
    at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:144)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:160)
    at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:380)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
    ... 7 more



    Can you please help me to solve the problem?

    ReplyDelete
  48. Hi,

    Your gave amazing explanation. I did follow your steps. But, when i run it below error is coming.

    Please help

    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$100(GeckoDriverService.java:38)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:91)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
    at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:245)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:220)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:215)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:211)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:124)
    at TestPackage.TestClass.main(TestClass.java:9)

    ReplyDelete
  49. Hi....I started learning Selenium webdriver and, this blog is very useful for basics who learning newly.

    I encounter the below error whil execute the above script. please check let me know if any configuration is missed

    Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at mytestpack.mytestclass.main(mytestclass.java:9)
    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

    ReplyDelete
  50. for people having errors in selenium firefox program you need driver manager that is hosted in github

    https://github.com/bonigarcia/webdrivermanager

    steps:

    1)you need the following dependency

    io.github.bonigarcia
    webdrivermanager
    1.4.9


    2) Your program looks like this
    MarionetteDriverManager.getInstance().setup();
    WebDriver driver = new FirefoxDriver();
    driver.get("http://only-testing-blog.blogspot.in");
    String i = driver.getCurrentUrl();
    System.out.println(i);
    driver.quit();

    3) just run the program

    following are other dependecies


    org.seleniumhq.selenium
    selenium-firefox-driver
    3.0.0-beta4


    org.seleniumhq.selenium
    selenium-api
    3.0.0-beta4



    ReplyDelete
  51. Hello,

    how do I set webdriver property . I have tried several formats and all fail

    ReplyDelete
  52. hi,

    i'm getting this issue as i run the test cases

    Exception in thread "main" org.apache.bcel.verifier.exc.AssertionViolatedException:
    FOUND:
    INTERNAL ERROR: Oops!
    Exiting!!

    at org.apache.bcel.verifier.exc.AssertionViolatedException.main(AssertionViolatedException.java:102)
    can anybody help on this.

    ReplyDelete
  53. I tried this but I'am facing a problem with the below exceptions.
    Could anyone help me on this?

    package mytestpack;



    public class mytestclass {

    public static void main(String[] args) {

    WebDriver driver = new FirefoxDriver();
    driver.get("http://only-testing-blog.blogspot.in");
    String i = driver.getCurrentUrl();
    System.out.println(i);
    driver.close();
    }
    }


    Description Resource Path Location Type
    FirefoxDriver cannot be resolved to a type mytestclass.java /testproject/src/mytestpack line 11 Java Problem
    FirefoxDriver cannot be resolved to a type mytestclass.java /testprojects/src/mytestpacks line 7 Java Problem
    The import org.openqa cannot be resolved mytestclass.java /testproject/src/mytestpack line 3 Java Problem
    The import org.openqa cannot be resolved mytestclass.java /testproject/src/mytestpack line 5 Java Problem
    The method close() is undefined for the type WebDriver mytestclass.java /testproject/src/mytestpack line 15 Java Problem
    The method get(String) is undefined for the type WebDriver mytestclass.java /testproject/src/mytestpack line 12 Java Problem
    The method getCurrentUrl() is undefined for the type WebDriver mytestclass.java /testproject/src/mytestpack line 13 Java Problem
    WebDriver cannot be resolved to a type mytestclass.java /testprojects/src/mytestpacks line 7 Java Problem

    ReplyDelete
  54. This is lovely. Thanks for sharing your knowledge.

    For MAC - after following same steps you will might get error.

    At this point, make sure you follow below steps

    brew install geckodriver
    export PATH=/my/firefox/path/bin:$PATH
    export PATH=/Users/geckodriver:$PATH

    ReplyDelete
  55. This is lovely. Thanks for sharing your knowledge.

    For MAC - after following same steps you will might get error.

    At this point, make sure you follow below steps

    brew install geckodriver
    export PATH=/my/firefox/path/bin:$PATH
    export PATH=/Users/geckodriver:$PATH

    ReplyDelete
  56. Just for new comer!!
    The below:
    System.setProperty("webdriver.gecko.driver","D:\\Selenium Files\\geckodriver.exe");
    //initialize firefox driver object to open firefox browser.
    WebDriver driver = new FirefoxDriver();

    should be:
    WebDriver driver;
    System.setProperty("webdriver.gecko.driver","D:\\Selenium Files\\geckodriver.exe");
    //initialize firefox driver object to open firefox browser.
    driver= new FirefoxDriver();

    Thank you Aravind G, God bless you.

    Mak

    ReplyDelete
  57. Can't get this to work. i am getting 4 compilation errors: 1) Firefox Driver cannot be resolved to a type. 2) The import org.openqa cannot be resolved. 3) The import org.openqa cannot be resolved. 4) WebDriver cannot be resolved to a type. Please advise!!!

    ReplyDelete
  58. Does not work for me. I am getting compile errors. 1) Firefox driver cannot be resolved to a type. 2) The import org.openqa cannot be resolved. 3) The import org.openqa cannot be resolved. 4) WebDriver cannot be resolved to a type.

    ReplyDelete