我使用Junit 4和selenium WebDriver和Eclipse在ubuntu上運行我的測試。
當我運行我的測試中,我有這樣的錯誤:Ubuntu上的JUnit 4(WebDriver)
> 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);
}
}
}
發生錯誤的位置? – e1che
後頁面加載 –