Selenium Java-[ArrayIndexOutOfBoundsException:1]

Selenium Java-[ArrayIndexOutOfBoundsException:1],java,arrays,selenium,Java,Arrays,Selenium,您好,我在JavaSelenium中使用以下方法。该方法在很多冲刺中都运行良好,然后突然停止工作并抛出以下错误:操作失败。页面控件:pagecontrols.CustomMethods,操作:getNumberOfElements,原因:[ArrayIndexOutOfBoundsException:1] 我发现了类似的案例,但无法将其与我自己的方法进行比较: public int getNumberOfElements(){ List<WebElement> childs

您好,我在JavaSelenium中使用以下方法。该方法在很多冲刺中都运行良好,然后突然停止工作并抛出以下错误:操作失败。页面控件:pagecontrols.CustomMethods,操作:getNumberOfElements,原因:[ArrayIndexOutOfBoundsException:1]

我发现了类似的案例,但无法将其与我自己的方法进行比较:

public int getNumberOfElements(){
    List<WebElement> childs = webDriver.findElements(By.xpath(webElement.toString().split(" -> xpath: ")[1].replaceFirst("(?s)(.*)\\]", "$1" + "")));
    int numofChildren = childs.size();
    return numofChildren;
    }
public int getNumberOfElements(){
List childs=webDriver.findelelements(By.xpath(webElement.toString().split(“->xpath:”)[1].replaceFirst((?s)(.*)\\]],“$1+”);
int numofChildren=childs.size();
归还儿童;
}

我知道错误是通过使用非法索引访问数组生成的,所以我查过:
(by.xpath(webElement.toString().split(“->xpath:”)[0]
您确定字符串包含文字
而不是类似的
?更一般地说,什么是
webElement
?@FedericoklezCulloca我的webelements是://div[@id='mainProducts'和@role='listbox']//下面的兄弟::div[@style='background-color:white;']但是,在执行此方法时,屏幕上只有一个这样的webelement可见。