Q:

How to print the contents in the "ui","li" tags using selenium web driver

I am a newbee to selenium tool.
I have a website with url : https://m.karmaloop.com/
I need to Print the contents in the Shop Mens Page like , Categories,Top Brands, New etc.
steps:
=====
1.Launch https://m.karmaloop.com/
2.Tap on Shop Mens image
3.User will be navigated to Shop Men's Page.
4.Fetch and display the contents like , Categories,Top Brands, New etc.

I have written the code for accessing it.But unfortunately it did not work.
Here is my code :
driver2.get(configuration.Home_url);
        driver2.findElement(By.xpath(configuration.Shopmens)).click();

        WebElement Mens_Object=driver2.findElement(By.id("browse-new-product"));

        System.out.println("clicked");

        List<WebElement> lists=Mens_Object.findElements(By.tagName("li"));

        System.out.println("captured  ul");

        lists.get(3).click();

        List<WebElement>  ListElements =lists.get(3).findElements(By.tagName("a"));

        System.out.println(ListElements.get(2).getText());

Can any one please help me to solve this task.?

A:

Use this code:-
List<WebElement> liElements = driver.findElements(By
                .xpath("//ul[@id='browse-new-product']/li"));

        System.out.println(liElements.size());

        for (int i = 1; i < liElements.size()+1; i++) {
            WebElement linkElement = driver
                    .findElement(By
                            .xpath("//ul[@id='browse-new-product']/li[" + i
                                    + "]/a"));

            System.out.println(linkElement.getText());
        }

