【问题标题】:IndexOutOfBoundsException: Index: 1, Size: 1IndexOutOfBoundsException:索引:1,大小:1
【发布时间】:2018-03-14 16:32:45
【问题描述】:
List<WebElement> filter_icons = (ArrayList<WebElement>) driver.findElements(By.xpath(PropertyFile.read_obj("CONFIGURATION_MAJORMGMT_FILTER_LIST")));
filter_icons.size();
log.info("Data passed in Name Filter");

// filter EmailID
filter_icons.get(0).click();
Common.filter_textbox(driver, Name,By.xpath("//input[@id='filterText']"));
Common.click_filterbutton(driver,By.xpath("//button[text()='Apply Filter']"));

// filter Title
filter_icons.get(1).click();
Common.filter_textbox(driver, Value,By.xpath("//input[@id='filterText']"));
Common.click_filterbutton(driver,By.xpath("//button[text()='Apply Filter']"));

第二次过滤器点击的问题,它给出了错误,

java.lang.IndexOutOfBoundsException

相同的代码完美地适用于其他方法。

【问题讨论】:

标签: java selenium selenium-webdriver indexoutofboundsexception


【解决方案1】:

错误 {{IndexOutOfBoundsException: Index: 1, Size: 1 }} 清楚地表明列表的大小是 1(意味着您只有索引 0 处的项目)并且您试图 获取索引 1 处不存在的项目。

你可以这样做

for (WebElement ele : filter_icons) {
    ele.click();
    Common.filter_textbox(driver, Name,By.xpath("//input[@id='filterText']"));
    Common.click_filterbutton(driver,By.xpath("//button[text()='Apply Filter']"));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-28
    • 2019-02-01
    • 2018-02-13
    • 2016-10-09
    • 2020-10-27
    • 2015-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多