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, 2019 in Selenium by Hussain
4,945 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);
    }
}

Hope this helps!

Check out this automation testing training and learn more.

Thanks!

answered Aug 14, 2019 by Abha
• 28,140 points

edited Jul 19, 2023 by Khan Sarfaraz

Related Questions In Selenium

0 votes
1 answer

Can anyone help me with Zomato login test script using Python Selenium Webdriver?

Hi Laxmikant, if you want to write ...READ MORE

answered Jul 29, 2019 in Selenium by Anvi
• 14,150 points
2,133 views
0 votes
1 answer

Getting error NoClassDeffound error while exceuting selenium script(created with maven) , please help me to resolve this

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap at org.openqa.selenium.remote.service.DriverService$Builder.<init>(DriverService.java:259) at ...READ MORE

answered Apr 20, 2020 in Selenium by celine
6,243 views
0 votes
0 answers

Could you please help me with some selenium projects along with source code?

I am learning selenium and  I have ...READ MORE

Mar 10, 2019 in Selenium by Mark
742 views
0 votes
2 answers

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,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
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,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 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, 2019 in Selenium by Abha
• 28,140 points
4,734 views
0 votes
1 answer

Automation script for handling Calendar on a webpage using Selenium Webdriver?

Hi Shruti, here's the automation script for ...READ MORE

answered Jun 4, 2019 in Selenium by Abha
• 28,140 points
2,748 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP