Wednesday, February 26, 2014

Validating an image--- with the xpath of an image.

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ImagevalidationinFirefox {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
WebDriver FF1; // Create WebDriver element
FF1= new FirefoxDriver(); //Create Firefox Webelement
FF1.get("http://www.homedepot.com"); //Open the homedepot.com website
//validating the homedepot logo it is an image.
if(FF1.findElement(By.xpath("//img[@src='http://www.homedepot.com/static/theme/v3/images/headerFooter/hd-logo.png']")).isDisplayed())
    System.out.println("image is displayed");
//The else statement never executes
else
    System.out.println("No, image is not dispalyed");
        //http://www.homedepot.com/static/theme/v3/images/headerFooter/hd-logo.png
    }
}

No comments:

Post a Comment