I would like to test an Image carousel using Selenium C#

An example of the type of the type of carousel can be found here: http://bxslider.com/

Maybe the test could click on the next image, assert that there is an image and then perhaps in the last image attempt to click on a link to lead us to a new page

Below is what I attempted so far but I have no idea to check an image is present and to click on the link on the last image

IList<IWebElement> Parent = Driver.Instance.FindElements(By.XPath("//*[@class='pagination']/li"));
        int ListCount = Parent.Count;

        for (int i = 0; i < ListCount; i++)
            var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(3));

            var arrow = Driver.Instance.FindElement(By.XPath(".//*[@id='cpBanners_ucc1_ctl00_rptSlides_hlProperty_0']"));

Any help would be much appreciated, Thanks

  • 1
    Not sure what you want to test: what are the actions and expected results? Do you want to test that image changes every X seconds? Nov 17 '14 at 17:38
  • Are you looking for ideas on what to test, or you already know what you want to test and need to know how to automate it? If you know specifically what to test, give us the steps and we can help identify how to automate it.
    – Sam Woods
    Nov 17 '14 at 18:59
  • Yes I would like to test that the image changes every X seconds.
    – BossMan
    Nov 18 '14 at 9:42

For testing the bxslider, you can use some of the following. Every image is in a LI element, so after each click you can test if the next LI has become visible (and the previous one invisible). This will get you the list (try using other locators than XPath when possible).

elements = driver.findElements(By.CssSelector("ul[class=\"bxslider\"] li"));

You might go about it like this: wait until the next image is shown. Either use the ExpectedCondition, see the original post in https://stackoverflow.com/questions/22646031/selenium-wait-until-element-is-not-visible or wait until the next image is visible:

wait.Until(drv => elements[1].Displayed);

And then check if the previous one is no longer displayed.

Alternatively, if you are aware of the sourcefiles' names, you can use those. As you know the number of elements (.Count property) you can easily test if the first image returns after you skip the last one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.