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

Answered

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.

RavinderReddy 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
9 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.

zavelevsky 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.get(“https://www.vodafone.in/pages/home_kar.aspx?cid=kar”);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(“//img[contains(@src,’../_layouts/images/vf/banners/herospace/923201430138PM_HB(1).jpg’)]”)));
if(driver.findElement(By.xpath(“//img[contains(@src,’../_layouts/images/vf/banners/herospace/923201430138PM_HB(1).jpg’)]”)).isDisplayed()){
System.out.println(“923201430138PM_HB(1).jpg Displayed”);
}else{
System.err.println(“Not displayed”);
}
driver.quit();

Rocky Doctor Answered on September 27, 2014.
Add Comment

Hi RavinderReddy,

Can you please post the HTML code ?

Thanks,
Vishal

vishaalcbe Doctor Answered on September 26, 2014.

@Vishal,

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

on September 27, 2014.

@Rocky

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

Cheers,
Vishal

on September 27, 2014.

@Vishal,

Please don’t take it personally, and everyone should know this: http://forumsqa.com/badges/. 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.

Agreed

on September 28, 2014.
Add Comment

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

anu17 Doctor Answered on September 26, 2014.
Add Comment

Hi,
Thank you all for your response.. Here is the site where images changes from time to time. Please go thru this.
https://uk.webuy.com/

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

RavinderReddy Train Answered on September 28, 2014.
Add Comment

Hi everyone,

After login I press ask question button but system shows red colour bar after few sec its gone. am not able ask question via ask question link, so am ask my question via your answer block

My question

I want to control TestNg framework using excel sheet

eg: 5 test case, i want run 3rd test case without edit code or anything do, directly i change in excel file and run batch file thats it.

Please give reference

12345 Default Answered on October 7, 2014.

Hello 12345,

Please create new question and post your code. Also please elaborate your question for Ex: What you are controlling in excelsheet and what you want to control, post the code so we have to change the code as per the your requirement.

Also I am able to create new question, please find the below screenshot.

RE: How to verify the Changing Images in a Website using Selenium Webdriver
on October 7, 2014.
Add Comment

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

RavinderReddy 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?

https://uk.webuy.com/

RavinderReddy 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;

@Test
public void sikuliCheck() throws FindFailed{

driver = new FirefoxDriver();
driver.get(“http://www.flipkart.com”);

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.click(loginLink);
screen.type(userEdit, “swastiksuman@gmail.com”);
screen.type(passEdit, “somepass”);

}

}

swastiksuman 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.