wait(...) 的所有变体都从以下代码中抛出以下异常。我做错了什么?
java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:485)
at LoginPage.main(LoginPage.java:29)
try
{
driver.get("http://domain:port/coco/webapp/login/login.faces");
driver.findElement(By.id("clientCode")).sendKeys("coco");
driver.findElement(By.id("systemCode")).sendKeys("consumer");
driver.findElement(By.id("userId")).sendKeys("ffadmin");
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.className("af_commandButton")).click();
driver.wait();
Assert.assertTrue(driver.getPageSource().contains("Administration"));
}
catch (Exception e)
{
e.printStackTrace();
}
最佳答案
你只能wait
如果您已使用 synchronized
为对象获取锁,则在对象上。
我不知道你是否打算使用wait
using WebDriver - 如果你是,你需要类似的东西:
synchronized (driver)
{
driver.wait();
}
但是,如果您正在等待某事发生,则更有可能是您打算使用的替代方法。也许WebDriverWait
?
关于java - driver.wait() 抛出 IllegalMonitorStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5858743/