Saturday, 21 June 2014

Display All Menu Items

package Webdriverprgs;

import java.awt.List;
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;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

public class displayallmenuitems {
    WebDriver driver;
   
  @Test
  public void f() {
   
 
      //int size=driver.findElements(By.xpath("//a[@class='NavLink']")).size();//to write our own xpath
      int size=driver.findElements(By.className("NavLink")).size();
      System.out.println("No of Main Menu's are "+ size );
      for (int i=1;i<size+1;i++){
      String xpath= "(//a[@class='NavLink'])[" + i + "]";
      // System.out.println("Xpath is" + xpath);
      System.out.println("Main Menu " + i+" is" + driver.findElement(By.xpath(xpath)).getText());
              }
  }
  @BeforeMethod
  public void beforeMethod() {
 
  driver=new FirefoxDriver();
  driver.get("http://www.espncricinfo.com/");
driver.manage().window().maximize();
  }

  @AfterMethod
  public void afterMethod() {
  }

}

No comments:

Post a Comment