Please help me with automation script for testing Carousel Rotation with Selenium Webdriver.

0 votes
Please help me with automation script for testing Carousel Rotation with Selenium Webdriver.
Aug 14 in Selenium by Hussain
85 views

1 answer to this question.

0 votes

Hey Hussain, you can use following lines of code to write automation script for testing Carousel Rotation in Selenium:

public class CarouselTest {

    public void test() {

        //This will get the number of items in the carousel
        String selector = "li[class^=a-carousel-card]";
        ArrayList items = driver.findElements(By.cssSelector(selector));

        ArrayList list1 = new ArrayList();
        String name;

        for (int i = 0; i < items; i++) {
            int index = i + 1;

            //This will get the name of each item in carousel
            name = driver.findElement(By.cssSelector(selector + "[" + index + "]")).getText();
            list1.add(name);
        }

        //Next we click on the arrow of the carousel
        driver.findElement(By.cssSelector("div[class^=a-carousel-col] a")).click();

        //Then we new items are loaded in the carousel following the click,
        //we get the names again

        ArrayList nextItems = driver.findElements(By.cssSelector(selector));

        ArrayList list2 = new ArrayList();

        String newName;

        for (int i = 0; i < nextItems; i++) {
            int index = i + 1;

            //This will get the name of each item in carousel
            newName = driver.findElement(By.cssSelector(selector + "[" + index + "]")).getText();
            list2.add(newName);
        }

        //Then we compare the two arrayLists are not the same
        ArrayList commonList = CollectionUtils.retainAll(list1, list2);

        Assert.assertTrue(commonList.size() == 0);
    }
}
answered Aug 14 by Abha
• 22,870 points

Related Questions In Selenium

0 votes
1 answer
+1 vote
0 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
555 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
890 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
553 views
0 votes
3 answers

Scripting Languages used with Selenium tool for Automation Testing

The biggest advantage of Selenium is that ...READ MORE

answered Aug 28 in Selenium by Abha
• 22,870 points
184 views
0 votes
1 answer