如何在单行和多列中传递值

问题描述 投票:0回答:1

我需要处理webtable来传递值特定列as here

 String p=" Ease 3.0   | $849";
 WebElement Product=driver.findElement(By.xpath("//h1[text()='"+p+"']//parent::div//following-sibling::div[1]//div[1]//div[2]"));

 WebElement findp=Product.findElement(By.tagName("tbody"));

 List<WebElement> great=findp.findElements(By.xpath("tr"));

 int rowcount=great.size();

 System.out.println(rowcount);

 for(int i=0;i<=great.size();i++)
 {
        XSSFRow foundRow =sheet.getRow(i);

        List<WebElement> column_row=great.get(i).findElements(By.tagName("td"));
        int columncount=column_row.size();

        System.out.println("total number of row"+rowcount+"columns are"+columncount);
}

但是我遇到了以下错误。请任何人帮忙。

FAILED:Allproduct java.lang.IndexOutOfBoundsException:索引:1,大小:1,位于java.util.ArrayList.rangeCheck(未知源)处java.util.ArrayList.get(未知源)

selenium web-applications testng
1个回答
0
投票

您正在尝试访问超出列表范围的索引。

for(int i=0;i<=great.size();i++)

您正在检查i小于或等于列表的大小,但这是错误的。

假定列表具有3个元素[1,2,3]。计数将返回3,但最后一个元素的索引为2(从零开始)。当您尝试访问索引3时,将引发异常。

© www.soinside.com 2019 - 2024. All rights reserved.