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.

asked Feb 9, 2017 at 9:28
3
  • 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. Commented Feb 9, 2017 at 10:33
  • @Alok The exception is thrown immediately opening FireFox. Commented Feb 9, 2017 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? Commented Feb 9, 2017 at 16:06

1 Answer 1

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();
 }
}
 }
answered Feb 10, 2017 at 5:46
1
  • The problem existed because I included geckodriver.exe in the referenced libraries of the project. Anyway, I fixed the problem. Commented Feb 10, 2017 at 9:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.