Wednesday, January 14, 2015

Selenium script to get table values

package Ecomm_selenium;

import java.util.List;

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

public class Tablevalues {

       /**
       * @param args
       */
       public static void main(String[] args) {
              // TODO Auto-generated method stub
           //String paths = ".//*[@id='fk-mainbody-id']/div/div[2]";       
           //String
             
              WebDriver d = new FirefoxDriver();
              d.get(site);
              //WebElement webtable = d.findElement(By.xpath(".//*[@id='grey-box']/div"));
              int RowIndex = 3;
              List<WebElement> Rowcount = d.findElements(By.xpath(".//*[@id='grey-box']/div/div["+RowIndex+"]"));
             
              System.out.println("No: of Rows in table:" + Rowcount.size());
                    
              //for(WebElement rowelem : Rowcount)
              for(int i=0; i <= RowIndex; i++)
              {
                     int ColIndex = 3;
                     for(int j = 0; j <= ColIndex; j++){
                           WebElement value = d.findElement(By.xpath(".//*[@id='grey-box']/div/div["+i+"]/div["+j+"]/p"));
                           System.out.println("Row" + i + "Column" + j + "Data" + value.getText());
                     }
                    
                     
              }
              d.quit();
       }
      
}

No comments:

Post a Comment