- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该元素已启用并显示。但是,当我尝试单击按钮元素时出现错误。
Error: java.lang.IllegalMonitorStateException
查看我的代码以获取更多详细信息。
Actions actions = new Actions(driver);
actions.moveToElement(element, element.getLocation().x, element.getLocation().y).wait(3000);
element.click();
最佳答案
根据 Java 文档 IllegalMonitorStateException抛出该异常表示一个线程试图在对象的监视器上等待,或者通知在不拥有指定监视器的情况下在对象的监视器上等待的其他线程。
public class IllegalMonitorStateException
extends RuntimeException
继承自类java.lang.Object的相关方法具体如下:
Object.notify()
:唤醒正在该对象监视器上等待的单个线程。Object.notifyAll()
:唤醒在此对象监视器上等待的所有线程。Object.wait()
:使当前线程等待,直到另一个线程调用 notify()
方法或 notifyAll(
)该对象的方法。Object.wait(long)
:导致当前线程等待,直到另一个线程调用 notify()
方法或 notifyAll()
该对象的方法,或者已经过了指定的时间。Object.wait(long, int)
:使当前线程等待,直到另一个线程调用 notify()
方法或 notifyAll()
该对象的方法,或者某个其他线程中断了当前线程,或者已经过了一定的实时时间。当您使用 Selenium 时这些 wait()
方法不能在这里使用,您需要使用 WebDriverWait与 ExpectedConditions 结合使用您可以使用以下解决方案:
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
关于单击 Facebook 发布按钮时出现 java.lang.IllegalMonitorStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57024840/
我是 Java 新手(也是 RoR 开发人员)。 我有一个简单的程序。球由球员共享。球应传给随机玩家。 好的,代码如下: class Ball { private int currentPl
我是否没有正确使用同步: 在下面的代码中我遇到了两个问题: 1.在将方法(designBusiness、createBusiness、sellBusiness)设置为 synchronized 时,就
我不完全理解wait和notify(Object)是如何工作的,结果我被迫瘦身将我的尝试记入以下代码部分。 Main.java: import java.util.ArrayList; class M
我有这个代码 if( id == 0 ||(id % 2) != 0){ System.out.println("test"); synchronized(lo
我是 Java 新手。我刚刚读了《java核心》这本书。我遇到了有关“条件和锁定”的问题。 我从书上敲了一段代码到eclipse中做了一些练习。 当我运行代码时,“sufficientFund.wai
我想模拟一个妈妈叫三个 child 吃饭,这是我的代码: class child extends Thread{ String name; mother mom; public
我正在尝试在新线程中调用方法,该方法将在使用 callable 延迟后返回一些东西。由于,它正在下降IllegalMonitorStateException 当我只创建类的实例,调用方法并且该方法将延
我已经使用 java 线程构建了生产者-消费者。生产者和消费者是两个不同的类,指的是单链表和对象锁。下面的实现有什么问题? Item Produced by Thread-0 Item 1 Item
我在我的代码中遇到了 IllegalMonitorStateException,我不确定为什么会收到它以及如何修复它。我当前的代码是并且错误发生在 try block 中: public stat
请向我解释为什么我的代码在等待函数中抛出 IllegalMonitorStateException ,据我所知,只有在同步部分未完成时才会发生这种情况? private void deliver(in
每当我调用pauseThread()时,它总是抛出IllegalMonitorStateException。 我在文档中注意到我需要拥有对象监视器才能使线程等待。 用这段代码 synchronized
我正在尝试学习java并发编程。请检查我的示例代码并帮助我理解为什么我会收到“java.lang.IllegalMonitorStateException”,即使我在同步上下文中调用了 wait()
我对监视器和条件变量不熟悉。我在监视器中使用锁定和条件变量。 public class Monitor { private final int piNumberOfPhilosopher
所以我正在尝试编写一个程序来打印出以下输出: 44 33 22 11 该程序应该是多线程的,并且必须使用锁来防止竞争条件。它还必须利用 Condition,以便当线程想要打印的数字与变量 thread
我对多线程了解甚少。 我期望下面的程序能够完美运行,但它不起作用并产生以下异常。 Exception in thread "Thread-1" java.lang.IllegalMonitorStat
我不完全理解wait和notify(Object的)的工作方式,因此,我不得不将尝试减少到以下代码部分。 Main.java: import java.util.ArrayList; class
void waitForSignal(){ Object ob =new Object(); synchronized (Thred.currentThread()) {
我收到一个 IllegalMonitorStateException,我觉得我无法阅读更多内容,所以我问是否有人知道我做错了什么。在计数器(门类中线程之间的共享资源)陷入等待状态后,我在程序运行结束时
我有一个程序可以模拟一艘船的大门。它们在线程中运行。这个想法是让它们在 run 方法中的随机时刻运行和暂停,以模拟路过的人。这是由所有线程完成的,同时主线程正在等待通知并检查船是否已满,当线程通知他们
我想在线程中运行的 Vector 中使用同步 我尝试使用两种方法,一种用于等待,另一种用于通知 我想从静态类调用notify方法这是我的线程代码: import java.io.IOException
我是一名优秀的程序员,十分优秀!