IllegalMonitorStateException
As per the Java Docs IllegalMonitorStateException 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.
public class IllegalMonitorStateException
extends RuntimeException
The relevant methods inherited from class java.lang.Object are as follows:
Object.notify()
: Wakes up a single thread that is waiting on this object's monitor.
Object.notifyAll()
: Wakes up all threads that are waiting on this object's monitor.
Object.wait()
: Causes the current thread to wait until another thread invokes the notify()
method or the notifyAll(
) method for this object.
Object.wait(long)
: Causes the current thread to wait until either another thread invokes the notify()
method or the notifyAll()
method for this object, or a specified amount of time has elapsed.
Object.wait(long, int)
: Causes the current thread to wait until another thread invokes the notify()
method or the notifyAll()
method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
As you are using Selenium these wait()
methods can't be used here and you need to use WebDriverWait in conjunction with ExpectedConditions and you can use the following solution:
WebElement element = driver.findElement(By.cssSelector("css_of_the_element"))
new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(element))).click().build().perform();
Here you can find a relevant discussion on Difference between driver.manage.wait(long timeout) and Explicit wait