Its now easy to verify the image height and width of an image on a web page using Selenium. Here is the code that verifies if the height of the image is between 595 and 686 px and width is 230 px.
decimal height = selenium.GetElementHeight("//img[@class='heroImageMain']");
decimal width = selenium.GetElementWidth("//img[@class='heroImageMain']");
Console.WriteLine("Hero Image dimensions:- " + width + " x " + height + " pixels.");
if ((height >= 595 && height <= 686) && (width == 230))
{
console.writeline(Testcase + "Hero image dimensions are invalid -> " + +width + " x " + height + " pixels.");
}
Submitted by: Horgan Barry
How did this solution work for you? Do you have a better alternative? Feel free to share your thoughts in comments section below.
