Unable to delete links in a loop

82 views
Skip to first unread message

testingzeal

unread,
Aug 27, 2018, 11:59:43 AM8/27/18
to webdriver
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 

Øystein Torvund

unread,
Sep 26, 2018, 4:58:59 AM9/26/18
to testingzeal, webd...@googlegroups.com
This is a coding problem and not a selenium problem. 

Read up on how loops work in your language. 

Hint: check your for loop..

From: webd...@googlegroups.com <webd...@googlegroups.com> on behalf of testingzeal <jsel...@gmail.com>
Sent: Monday, August 27, 2018 3:59 PM
To: webdriver
Subject: [webdriver] Unable to delete links in a loop
 
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at https://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

raja

unread,
Dec 3, 2018, 1:45:25 AM12/3/18
to webdriver
Please change your loop as below

for (int pos = 0; pos < = numberOfElementsFound -1    ; pos++) {

Regards,
Rajasekhar. 
Reply all
Reply to author
Forward
0 new messages