尝试这样的事情:
public static int DEFAULT_IMPLICIT_WAIT = 30;
getElementByLocator( By.cssSelector("span.ui-icon.ui-icon-closethick")).click();
从这个方法:
public static WebElement getElementByLocator( By locator ) {
long startTime = System.currentTimeMillis();
driver.manage().timeouts().implicitlyWait( 5, TimeUnit.SECONDS );
WebElement we = null;
boolean unfound = true;
while ( unfound ) {
try {
we = driver.findElement( locator );
unfound = false; // FOUND IT
} catch ( StaleElementReferenceException e ) {
unfound = true;
try {
Thread.sleep(4000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
// and finally the cleanup
driver.manage().timeouts().implicitlyWait( DEFAULT_IMPLICIT_WAIT, TimeUnit.SECONDS );
return we;
}