driver.wait()抛出IllegalMonitorStateException [英] driver.wait() throws IllegalMonitorStateException

查看:175
本文介绍了driver.wait()抛出IllegalMonitorStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wait(...)的所有变体都会从以下代码中抛出以下异常。我做错了什么?

All the variations of wait(...) are throwing the below exception from the following code. What am I doing wrong?

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();
        }


推荐答案

你只能 等待 如果你使用 synchronized 获得了对象的锁定。

You can only wait on an object if you've acquired the lock for it using synchronized.

我不知道知道你是意味着使用等待使用WebDriver - 如果你是,你需要这样的东西:

I don't know whether you're meant to use wait using WebDriver - if you are, you'd need something like:

synchronized (driver)
{
    driver.wait();
}

然而,如果你正在等待某事发生,那么更有可能你可以使用另一种方法。也许 WebDriverWait

However, if you're waiting for something to occur, it's more likely that there's an alternative method you're meant to be using. Perhaps WebDriverWait?

这篇关于driver.wait()抛出IllegalMonitorStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆