How to check all elements in a <ul> list using Selenium WebDriver? How to check all elements in a <ul> list using Selenium WebDriver? selenium selenium

How to check all elements in a <ul> list using Selenium WebDriver?


Webdriver has findElements API, which can be used for this purpose..

List<WebElement> allElements = driver.findElements(By.xpath("//div[@id='...']/ul/li")); for (WebElement element: allElements) {      System.out.println(element.getText());}


Your initial code might work if you put the index i out of the string like so:

try {    for (int i=0; i<100; i++) {        driver.findElement(By.xpath("//div[@id='...']/ul/li["+i+"]"));    }}catch {...}


List<WebElement> allElements = driver.findElements(By.xpath("//div[@id='...']/ul/li"));int s=allElements.size();for(int i=1;i<=s;i++){    allElements = driver.findElements(By.xpath("//div[@id='...']/ul/li"));    allElements.get(i).click();}

Use this