[Solved] How to count total number of products on webpage and verify if those are correct with Selenium webdriver in Java? [closed]


The below java code will help you do the task

Here we create a driver instance go to the website url take all the products into a list and compare it with the text “1-15 of 38 Matching Products”

public static void main(String[] args) {

        WebDriver driver=new FirefoxDriver();

        driver.get("http://www.samsung.com/us/video/home-audio/all-products");

        List products = driver.findElements(By.className("product-image"));

        String pagination_no[]=driver.findElement(By.xpath("//*[@id='category_filter']/section/div[1]/div/div[1]/h1")).getText().split(" ");

        String[] pagination=pagination_no[1].split("-");

        Assert.assertEquals(Integer.parseInt(pagination[1]),products.size());       

       }
}

3

solved How to count total number of products on webpage and verify if those are correct with Selenium webdriver in Java? [closed]