下面的代码抛出了' stale element reference: element is not attached to The page document '
如何处理错误消息并将结果显示为传递
动作-下面的代码正在添加一个图像(可以是一个或多个)在另一个图像
public void click_on_the_Add_to_collection_button_displaying_down_below_the_assert() {
List<WebElement> all_colection = driver.findElements(By.xpath("//li//button[@class='icon-button ' and @title='Add To Collection']"));
int collection_size = all_colection.size();
System.out.println("the collection size is " + collection_size);
Random ran = new Random();
all_colection.get(collection_size - 1).click();
crate_new_colection.sendKeys("newcollection#1");
}
用try..catch
换行,如下所示:
public void click_on_the_Add_to_collection_button_displaying_down_below_the_assert() {
try{
List<WebElement> all_colection = driver.findElements(By.xpath("//li//button[@class='icon-button ' and @title='Add To Collection']"));
int collection_size = all_colection.size();
System.out.println("the collection size is " + collection_size);
Random ran = new Random();
all_colection.get(collection_size - 1).click();
crate_new_colection.sendKeys("newcollection#1");
}catch (StaleElementReferenceException e){
System.err.println("Skipping the exception. Do not let it get down stack.");
}
}
注:-我保持你的蛇的情况不变,但请不要在Java中使用类似python的代码风格。