How to verify the Changing Images in a Website using Selenium Webdriver


Hi All,
In our application there is a scenario like ,there are some images which changes continuously from time to time.. How should we verify those images whether they are present on website or not?
Please help me.

Train Asked on September 26, 2014 in Selenium WebDriver.

Nice question (Up vote for this) and have you tried this? or directly you need code?.

on September 27, 2014.

Since this question is very old, Is this still open for discussion, I found near by one working answer to this problem.  ???

on April 22, 2015.
Add Comment
  • 8 Answer(s)
    Best answer

    I’d like to suggest a general and more robust approach towards such dynamic behavior.
    I dislike using waits and timeouts in hope that something will be ready – it’s error prone and the best results are achieved by a bit of cooperation with the developers.
    What the developers need to do is:
    – when the URL contains a special query parameter – for example /?test=true – the application/site is under test mode.
    – In test mode – a child element called <test> is appended under the <body> element.
    – To use you images example – whenever an image is being displayed – a test event is sent to announce it – and the image is not changed until the event is handled.
    – Test even is sent by adding a child element under <test> element. You test code reads the element, handles it and deletes it – allowing the image gallery to move on.

    You might get away with simple timeouts when doing functional testing – but once you start running visual tests and take screenshots you’ll need the ability to “pause” the site’s state until you’re done and ready to move on.

    Train Answered on December 15, 2014.

    Thank you Zavelevsky..

    on December 16, 2014.
    Add Comment

    Hi Ravinder Reddy,

    To verify whether image is present or displayed or not, please use below code sample. May this will help for you.

    Absolute xpath is not good when you have dynamic identifiers (As I know).

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    WebDriverWait wait = new WebDriverWait(driver, 30);
    System.out.println(“923201430138PM_HB(1).jpg Displayed”);
    System.err.println(“Not displayed”);

    Doctor Answered on September 27, 2014.
    Add Comment

    Hi RavinderReddy,

    Can you please post the HTML code ?


    Doctor Answered on September 26, 2014.


    This is not a solution, requesting you to use comment option if you want any other details.

    on September 27, 2014.


    Thanks to let me know good piece of info. But there’ve been numerous instances of people asking to post the HTML.


    on September 27, 2014.


    Please don’t take it personally, and everyone should know this: If we can able to comment it then we can go with comment option. If any one don’t know then please inform to him/her. And many people are not accepting the answer also 🙁 .

    I feel moderator need to give comment permission for all, because new users are commenting in the answer column/option.

    on September 27, 2014.


    on September 28, 2014.
    Add Comment

    You can you the absolute  xpath of web element to locate the image.

    Doctor Answered on September 26, 2014.
    Add Comment

    Thank you all for your response.. Here is the site where images changes from time to time. Please go thru this.

    @Rocky I didn’t try your solution as I was not in office.

    Train Answered on September 28, 2014.
    Add Comment

    Sorry.. The provided solutions are not working.. I can’t able to find the solution.. Please anyone help me..

    Train Answered on October 9, 2014.

    It was working fine for me. Please dig in depth.

    on October 9, 2014.

    Also please use comment option.

    on October 9, 2014.

    Yes, the solution was very good.

    on October 9, 2014.
    Add Comment

    You must have 100 points to add comments…
    I didn’t have those many points to comment.. and I don’t have any other option other than this.
    The provided solution is  not working for me .could you please try on this site  for changing images?

    Train Answered on November 4, 2014.
    Add Comment

    If you have the image that has to be compared then, use sikuli jar. You can take the image you want to compare and save it in a location within your framework. On runtime, you can use it to compare it in the screen.

    In the below example we use image objects to set the username, password in Flipkart.
    Similarly you can use it to verify if an image exists.

    For example:
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.sikuli.script.FindFailed;
    import org.sikuli.script.Pattern;
    import org.sikuli.script.Screen;
    import org.testng.annotations.Test;
    public class AppTest{

    WebDriver driver;

    public void sikuliCheck() throws FindFailed{

    driver = new FirefoxDriver();

    Screen screen = new Screen();

    //Images of the WebEdits and WebButtons
    Pattern loginLink = new Pattern(“V:/MyWorkspace/SikuliTest/src/test/java/imageObjects/Login.PNG”);
    Pattern userEdit = new Pattern(“V:/MyWorkspace/SikuliTest/src/test/java/imageObjects/Username.PNG”);
    Pattern passEdit = new Pattern(“V:/MyWorkspace/SikuliTest/src/test/java/imageObjects/Username.PNG”);

    screen.wait(loginLink, 30);;
    screen.type(userEdit, “”);
    screen.type(passEdit, “somepass”);



    Train Answered on August 6, 2015.

    Cool.Thank You Somuch Swastik.

    on August 13, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.