public void capacitySelection(String capacity){ WebDriverWait wd = new WebDriverWait(driver, 180); List cList = wd.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@data-name='Capacity_s']/div"))); int i=1; for(WebElement we:cList){ WebElement select= wd.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@data-name='Capacity_s']/div["+ i++ +"]/label"))); if(select.getText().contains(capacity)){ select.click(); break; } } }