0

I was trying to automate to select drop down option with set<WebElement> , but while iterating it gives error as NullPointerException . I same tried with List<WebElement> , It works fine.

UserPageObject.java
----------------------------

 @FindAll({@FindBy(xpath ="//li[@role='option']/span[@class='ng-star-inserted']")})
    private Set<WebElement> DropDownElementStatus;

 public Set<WebElement> getDropDownElementStatus() {
        return DropDownElementStatus;
    }

    public void setDropDownElementStatus(Set<WebElement> dropDownElementStatus) {
        DropDownElementStatus = dropDownElementStatus;
    }


 ActionsUtilities.java 
---------------------------

public void AllDropDownSetElements(Set<WebElement> dropDownsElements, String DropDownOption ){
        Iterator<WebElement>  dropDownIteratorElements= dropDownsElements.iterator(); //getting error as NullPointerException on this line
        while(dropDownIteratorElements.hasNext())
        {
            WebElement element= dropDownIteratorElements.next();
            if(element.getText().trim().equals(DropDownOption))
                element.click();
        }
    }   



UserStepDefifnation.java
-----------------------------

objectList.getActionsUtilities().AllDropDownSetElements(objectList.getUserPageObject().getDropDownElementStatus(),"INACTIVE"); 
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Pralhad P
  • 29
  • 3

1 Answers1

0

Just like findElements() returns a List of WebElements:

java.util.List<WebElement> findElements​(By by)

Annotation Type FindAll() is used to mark a field on a Page Object to indicate that lookup should use a series of @FindBy tags. It will then search for all elements that match any of the FindBy criteria. However, elements are not guaranteed to be in document order.

@FindAll({@FindBy(xpath ="//li[@role='option']/span[@class='ng-star-inserted']")})
    private List<WebElement> DropDownElementStatus;

It can be used on a types as well as follows:

@FindAll({@FindBy(how = How.ID, using = "foo"),
          @FindBy(className = "bar")})
      

To conclude, @FindAll would return a List but not a Set, which you have to incorporate within yours tests.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352