Selenium 从集合中迭代webelement时将错误获取为java.lang.NullPointerException<;WebElement>;使用FindAll和PageObject
我试图用set自动选择下拉选项,但在迭代过程中,它给出的错误为NullPointerException。我试过同样的列表,效果很好Selenium 从集合中迭代webelement时将错误获取为java.lang.NullPointerException<;WebElement>;使用FindAll和PageObject,selenium,selenium-webdriver,collections,pageobjects,findall,Selenium,Selenium Webdriver,Collections,Pageobjects,Findall,我试图用set自动选择下拉选项,但在迭代过程中,它给出的错误为NullPointerException。我试过同样的列表,效果很好 UserPageObject.java ---------------------------- @FindAll({@FindBy(xpath ="//li[@role='option']/span[@class='ng-star-inserted']")}) private Set<WebElement> DropDo
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");
UserPageObject.java
----------------------------
@FindAll({@FindBy(xpath=“//li[@role='option']]/span[@class='ng-star-inserted']]))
私有设置DropDownElementStatus;
公共集getDropDownElementStatus(){
返回DropDownElementStatus;
}
public void setDropDownElementStatus(设置dropDownElementStatus){
DropDownElementStatus=DropDownElementStatus;
}
ActionsUtilities.java
---------------------------
public void AllDropDownSetElements(设置DropDownElements、字符串DropDownOption){
迭代器dropDownIteratorElements=DropdownElements.Iterator();//将错误获取为此行的NullPointerException
while(dropDownIteratorElements.hasNext())
{
WebElement=dropDownIteratorElements.next();
if(element.getText().trim().equals(DropDownOption))
元素。单击();
}
}
userstepdefination.java
-----------------------------
objectList.getActionsUtilities().AllDropDownSetElements(objectList.getUserPageObject().getDropDownElementStatus(),“非活动”);
就像返回s的列表一样:
它可用于以下类型:
@FindAll({@FindBy(how = How.ID, using = "foo"),
@FindBy(className = "bar")})
总之,@FindAll
将返回一个列表,但不是一个集合,您必须将其合并到测试中
@FindAll({@FindBy(xpath ="//li[@role='option']/span[@class='ng-star-inserted']")})
private List<WebElement> DropDownElementStatus;
@FindAll({@FindBy(how = How.ID, using = "foo"),
@FindBy(className = "bar")})