Java Ubuntu上的JUnit4(WebDriver)

Java Ubuntu上的JUnit4(WebDriver),java,selenium-webdriver,ubuntu-12.04,junit4,selenium-grid,Java,Selenium Webdriver,Ubuntu 12.04,Junit4,Selenium Grid,我使用JUnit4、SeleniumWebDriver和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.

我使用JUnit4、SeleniumWebDriver和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);
    }   
  }
}

这是一个示例:
org.openqa.selenium.StaleElementReferenceException

WebElement element = driver.findElement(By.id("input123")); // get the input 
WebElement button= driver.findElement(By.id("btn123")); // this button sends the form
button.click();
element.sendKeys("the cache is already released.."); // error here
因此,我认为这来自url中加载的

driver.get(baseUrl + "/QD2/pages/accueil/login.xhtml#loaded");
试着不用它,告诉我怎么了


更新:

尝试使用如下等待:

[...]
WebElement login = (new WebDriverWait(driver, 10))
              .until(ExpectedConditions.presenceOfElementLocated(By.id("login")));
login.sendKeys("admin");
[...]

但通常情况下等待将无济于事,因为当您通过naviguate将源更改为另一页或发送表单等时,会发生此错误。

错误发生在哪里?当我累了,没有加载页面,但我使用>线程。睡眠(1000);berof>driver.get(baseUrl+“/QD2/pages/acueil/login.xhtml已加载”);而且它工作了,谢谢你的帮助:)