Ara*_*ram 8 java testing selenium webdriver selenium-webdriver
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();
}
Run Code Online (Sandbox Code Playgroud)
Jon*_*eet 23
wait
如果您已经使用了锁定对象,则只能在对象上synchronized
.
我不知道你是否会意味着使用wait
使用webdriver的-如果你是,你需要这样的:
synchronized (driver)
{
driver.wait();
}
Run Code Online (Sandbox Code Playgroud)
但是,如果您正在等待某些事情发生,那么您更有可能会使用另一种方法.也许WebDriverWait
吧?
我希望这可以帮助你
driver.manage().timeouts().implicitlyWait(long time, java.util.concurrent.TimeUnit unit);
Run Code Online (Sandbox Code Playgroud)
要么
WebDriverWait wait = new WebDriverWait(driver, long timeOutInSeconds);
WebElement element = wait.until(presenceOfElementLocated(org.openqa.selenium.By locator));
Run Code Online (Sandbox Code Playgroud)
请注意,我没有执行此代码,因为我没有webdriver,但我在引用javadocs后写了这个.
有关详细信息,请参阅javadocs.