Showing posts with label Breadcrumb. Show all posts
Showing posts with label Breadcrumb. Show all posts

Monday, May 12, 2014

How to verify BreadCrumb ?

ex- Home>Services>Enterprise Web, this kind of sequence is called as breadcrumb.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class BreadCrumb {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.etouch.net/home/index.html");
        WebElement service = driver.findElement(By.xpath("//a[text()='Services']"));
        Actions act = new Actions(driver);
        act.moveToElement(service).perform();
        driver.findElement(By.xpath("//li[a[text()='Services']]//a[text()='Enterprise Web']")).click();
       
       
        String breadcrumb = driver.findElement(By.xpath("//div[@class='breadcrumb']")).getText();
        System.out.println(breadcrumb);
       
        String lastBreadcrumb = driver.findElement(By.xpath("//div[@class='breadcrumb']/span[last()]")).getText();
        System.out.println(lastBreadcrumb);
        if(lastBreadcrumb.equals("Enterprise Web")){
            System.out.println("bread crumb is in correct order.");
        }else{
            System.out.println("bread crumb is not in correct order.");
        }
    }
}