I'm getting the below error when i try to perform sample search on google

1486404621556 geckodriver INFO Listening on

Feb 06, 2017 11:10:22 AM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end

1486404622116 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe

1486404622117 geckodriver::marionette INFO Connecting to Marionette on localhost:54870

1486404623314 Marionette INFO Listening on port 54870

Feb 06, 2017 11:10:24 AM org.openqa.selenium.remote.ProtocolHandshake createSession

**INFO: Detected dialect: W3C

Exception in thread "main" java.lang.IllegalMonitorStateException at java.lang.Object.wait(Native Method) at TestGoogleSearch.main(TestGoogleSearch.java:24)**

The commands executed are below :

import    org.openqa.selenium.By;
import     org.openqa.selenium.JavascriptExecutor;
import     org.openqa.selenium.WebDriver;
import     org.openqa.selenium.WebElement;
import     org.openqa.selenium.firefox.FirefoxDriver;

public class TestGoogleSearch {

public static void main(String[] args) throws InterruptedException {

    // declaration and instantiation of objects/variables

    WebDriver driver = new FirefoxDriver();


    String baseUrl = "https://www.google.com";

    String actualTitle = "";

    // launch Firefox and direct it to the Base URL

    // get the actual value of the title
   actualTitle = driver.getTitle();


    WebElement wb=driver.findElement(By.name("q"));


     //close Firefox

    // exit the program explicitly



As soon it launches the google website and before it types anything in search, I get the above error as mentioned above

Installed Jars/Software :

     1. jdk-8u111-windows-x64

     2. selenium-server-standalone-3.0.1

     3. geckodriver

     4. Version: Kepler Service Release 1

    5. Build id: 20130919-0819

    6. Firefox Version : 51.0.1(32 bit)
| improve this question | | | | |
  • It worked for me with fireFox 60.0.2 and geckodriver V0.20.1, after removing the wait time. – Dipin Jun 11 '18 at 2:33
  • I have tried with thread. sleep too but , getting the same error. It's coming only in Internet Explorer for other browsers it works fine. – Jeesha Simson May 8 at 8:10

The exception is an IllegalMonitorStateException which is:

Thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor.

This was caused by your code driver.wait(5000);

Try changing it to Thread.sleep(5000);

Do keep in mind that using Sleep() is not preffered and you should instead wait for a condition. Example from SeleniumHQ:

WebDriver driver = new FirefoxDriver();
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.