我使用 Junit 4 和 selenium WebDriver 和 Eclipse 在 ubuntu 上运行我的测试。
当我运行我的测试时,我有这个错误:
> org.openqa.selenium.StaleElementReferenceException: Element not found
> in the cache - perhaps the page has changed since it was looked up
当我调试我的测试时,它可以工作。
这是我的测试:
package com.QD2.Login;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://localhost:8088/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test public void testUntitled() throws Exception {
driver.get(baseUrl + "/QD2/pages/accueil/login.xhtml#loaded");
//driver.findElement(By.id("login")).clear();
driver.findElement(By.xpath("//*[@id='login']")).sendKeys("admin");
//driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("admin");
driver.findElement(By.id("loginButton")).click();
}
@After public void tearDown() throws Exception {
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}