-1

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

1486404621556 geckodriver INFO Listening on 127.0.0.1:20799

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
    System.setProperty("webdriver.gecko.driver","C:\\javeed\\Automation\\geckodriver.exe");

    WebDriver driver = new FirefoxDriver();


    driver.manage().window().maximize();

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

    String actualTitle = "";

    // launch Firefox and direct it to the Base URL
    driver.get(baseUrl);

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

    driver.wait(5000);

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

    wb.sendKeys("test");

     //close Firefox
    driver.close();

    // exit the program explicitly
    System.exit(0);


}

}

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)
  • 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
1

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();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

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.