1

I'm using selenium 3.0.1 and java client library 3.0.1. I'm using the following code.

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

public class UserActions2 {

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

    System.setProperty("webdriver.gecko.driver","geckodriver.exe");
    WebDriver driver = new FirefoxDriver();

    driver.navigate().to("https://www.google.co.in/");
    driver.manage().window().maximize();
    String str = driver.getCurrentUrl();
    System.out.println("The current URL is " + str);
    }
}

And getting the error after FireFox launch

Exception in thread "main" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at Actions.UserActions2.main(UserActions2.java:20)

I have no clue for this error. I checked online, But there is No help.

  • At what line of code is this exception thrown? I would suggest you to wait before fetching the String str = driver.getCurrentUrl(); so that the webpage is loaded. – Alok Feb 9 '17 at 10:33
  • @Alok The exception is thrown immediately opening FireFox. – Raghu Feb 9 '17 at 11:31
  • Your question doesn't include 20 lines of code but your error is on line 20 according to the stack trace. What line of code is actually throwing the error? – kirbycope Feb 9 '17 at 16:06
1

I have run given above code and its running fine.

Mostly here might have configuration problem.

Working configuration of my system :

  1. JDK 1.8 installed and added JAVA_HOME env variable and in path. Refer

  2. Selenium Webdriver version 3.0 + Download

  3. Firefox latest version (v50 or more) Download and Install

  4. Download latest Geckodriver from Here. And put is in root directory of your project. If code is require path of Geckodriver then follow this

My Working code :

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

public class UserActions2
{

public static void main(String[] args)
{
    try
    {
        System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
        WebDriver driver = new FirefoxDriver();

        driver.navigate().to("https://www.google.co.in/");
        driver.manage().window().maximize();
        String str = driver.getCurrentUrl();
        System.out.println("The current URL is " + str);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

}
 }
  • The problem existed because I included geckodriver.exe in the referenced libraries of the project. Anyway, I fixed the problem. – Raghu Feb 10 '17 at 9:02

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.