I have a scenario that creates links and at the end of the test i need to delete them all. I have a loop to delete the links that is given below and it is not deleting the last link. Can i get help on this?
// If i have two links it is deleting only one link and doesn't throw any exception or error.
public void deleteFav() throws Exception
{
CommonUtils.waitFor(2);
CommonUtils.linkOrButtonClick(editFavoriteList);
int numberOfElementsFound = getNumberOfElementsFound(By.cssSelector(".FavLinkColumn > a.RemoveFav"));
System.out.println(" Links to delete : "+numberOfElementsFound);
for (int pos = 0; pos < numberOfElementsFound -1 ; pos++) {
if (getElementWithIndex(By.cssSelector(".FavLinkColumn > a.RemoveFav"), pos).isDisplayed())
{
System.out.println(pos);
System.out.println(getElementWithIndex(By.cssSelector(".FavLinkColumn > a.RemoveFav"), pos).getText());
getElementWithIndex(By.cssSelector(".FavLinkColumn > a.RemoveFav"), pos).click();
System.out.println(pos + " : Clicked");
}
CommonUtils.waitFor(1);
}
}
====
public int getNumberOfElementsFound(By by) {
return CommonUtils.driver.findElements(by).size();
}
public WebElement getElementWithIndex(By by, int pos) {
return CommonUtils.driver.findElements(by).get(pos);
}
=====console
Links to delete : 2 //
0
bvcb
0 : Clicked
IT IS NOT ENTERING ON Pos =1