Java 正在获取以下代码的过时引用异常。我正在使用for循环:-(
我已经编写了用于比较日期的代码,并根据时间对对象执行了取消操作。我想取消UI上显示的所有对象。但我无法取消所有对象,因为我遇到了过时的引用异常。请帮助Java 正在获取以下代码的过时引用异常。我正在使用for循环:-(,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我已经编写了用于比较日期的代码,并根据时间对对象执行了取消操作。我想取消UI上显示的所有对象。但我无法取消所有对象,因为我遇到了过时的引用异常。请帮助 List<WebElement> EachbookedAppointment = driver.findElements(By.xpath(prop.getProperty("eachbookedappointment"))); System.out.println(EachbookedAppointment.size()); f
List<WebElement> EachbookedAppointment = driver.findElements(By.xpath(prop.getProperty("eachbookedappointment")));
System.out.println(EachbookedAppointment.size());
for(int i=0; i< EachbookedAppointment.size();i++)
{
WebElement AppointmentStatus =EachbookedAppointment.get(i).findElement(By.xpath(prop.getProperty("AppointmentStatus")));
System.out.println(AppointmentStatus.getText());
if(AppointmentStatus.getText().equalsIgnoreCase("Scheduled"))
{
String bookingTime = EachbookedAppointment.get(i).findElement(By.xpath("//*[@class ='col-sm-10 time-col appPadding']/span")).getText();
String year = "2016 ";
StringBuilder sb = new StringBuilder();
System.out.println(bookingTime);
sb.append(year).append(bookingTime);
String UIDate = sb.toString() ;
System.out.println(UIDate);
Date date2 = sdfAmerica.parse(UIDate);
//String appointmentTime =
//sdfAmerica.setTimeZone(TimeZone.getTimeZone("America/New_York"));
Date onedaybackdate = DateUtils.addHours(date, -24);
System.out.println(date2 + "It is UI date");
TimeZone.getTimeZone("IST");
if(date2.before(Currentdate) && date2.after(onedaybackdate)){
System.out.println(Currentdate + "comes after " + onedaybackdate);
//EachbookedAppointment.get(i);//.findElement(By.xpath(prop.getProperty("CancelAppointment")));
WebElement element = (new WebDriverWait(driver, 20)).until(ExpectedConditions.elementToBeClickable(By.xpath(prop.getProperty("CancelAppointment"))));
//driver.findElement(By.xpath(prop.getProperty("CancelAppointment"))).click();
element.click();
waitUntilSpinnerIsDisplayed();
Assert.assertEquals(driver.findElement(By.xpath(prop.getProperty("AlertMessage"))).getText(), Constant.Cancelwithin24hourMessage);
}
else if(date2.after(Currentdate) || date2.before(onedaybackdate))
{
System.out.println(date2 + " UI displayed date ");
EachbookedAppointment.get(i).findElement(By.xpath(prop.getProperty("CancelAppointment"))).click();
//WebElement element = (new WebDriverWait(driver, 20)).until(ExpectedConditions.elementToBeClickable(By.xpath(prop.getProperty("CancelAppointment"))));
//driver.findElement(By.xpath(prop.getProperty("CancelAppointment"))).click();
WebElement CancelYes = (new WebDriverWait(driver, 20)).until(ExpectedConditions.elementToBeClickable(By.xpath(prop.getProperty("CancelYes"))));
CancelYes.click();
waitUntilSpinnerIsDisplayed();
WebElement Alert = (new WebDriverWait(driver, 20)).until(ExpectedConditions.elementToBeClickable(By.xpath(prop.getProperty("AlertMessage"))));
System.out.println(Alert.getText());
//Assert.assertEquals(driver.findElement(By.xpath(prop.getProperty("AlertMessage"))).getText(), Constant.CancelAlertMessage);
waitUntilSpinnerIsDisplayed();
}
}
}
List EachbookedAppointment=driver.findElements(By.xpath(prop.getProperty(“EachbookedAppointment”));
System.out.println(eachbookedappoint.size());
for(int i=0;i
如果您识别selenium中的任何元素并在以后对其进行修改,则会出现此错误
在您的例子中,列表包含所有元素(eachbookedappoint),稍后您提到要选择“取消”,我假设此项已被修改或删除。这破坏了我们先前找到的列表的完整性,因此您将获得此异常
提示:
get(0)
更改所有get(I)
。因此,您每次都将对列表的第一个元素进行操作,而由于我们在循环中取消它,因此每次都会更改您需要记住的唯一一件事是,如果您的WebElement被修改,您将收到此错误。在您单击“取消”后,此对象是否会更改或从列表中删除?发布错误跟踪确认。现在它正在工作