Hi Mrudula,
Could you please explain your scenario, for which items you want to make the list.
Thanks & Regards,
Mohit Kumar Mongia
I have modified your code to print the list of brands available on the page. Please check and let me know if you are looking for the same thing
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class carwale {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://carwale.com");
driver.findElement(By.xpath(".//*[@id='globalcity-popup']/div[1]/div[1]")).click();
System.out.println("pop up closed");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='nav']/ul/li[3]/a/span[2]")).click();
System.out.println("new cars clicked");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='nav']/ul/li[3]/ul/li[1]/a")).click();
System.out.println("clicked on find cars");
driver.findElement(By.xpath("html/body/div[9]/section[1]/div[1]/div/div[1]/ul/li[1]"));
System.out.println("brandtab select");
List<WebElement> brands = driver.findElements(By.xpath("//*[@id='brand-type']/div[1]/ul[1]/li"));
for (int i = 0; i < brands.size(); i++) {
System.out.println(brands.get(i).getText());
}
}
}