I'm adding a bunch of people to a list and I want to remove them from the list later. I've written a method that clicks on a standard X element to remove the users. My problem is that when I get to a point where there are no more instances of the X element to click on I get an error as follows:
"[31morg.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[3]/ul/li/div/div/img"} "
But isn't that the way I'm coming out of my While loop? When the element = null and therefore the condition is false shouldn't the while loop just end and not kick out an error message?
public class PrivacyList extends FluentPage {
@FindBy(xpath="//div[3]/ul/li/div/div/img")
private FluentWebElement XIcon ;
public void removeUserFromlist(){
while(XIcon!= null){
System.out.println("XICON is displayed");
XIcon.click();
System.out.println("XICON was clicked");
}
System.out.println("Users Removed");
}
}
Thanks