read specific row in a webtable using webdriver

'''''Read data from a web table  specific row / columns using webdriver
    import java.util.List;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class webdr_table
    {
        public static void main(String[] args) throws Exception
        {
            String str,found="false";
            FirefoxDriver fd=new FirefoxDriver();
            fd.get("http://content.icicidirect.com/newsiteContent/Market/MarketStats.asp?stats=DailySharePrices");
            Thread.sleep(5000);
            WebElement table=fd.findElement(By.id("gridSource"));
         
            List rows=table.findElements(By.tagName("tr"));
            for(WebElement row : rows)
            {
                List cols=row.findElements(By.tagName("td"));
                for(WebElement col : cols)
                {
                    str=col.getText().trim();
                    if(str.matches("ABB"))
                    {
                        List vals=row.findElements(By.tagName("td"));
                        for(WebElement v:vals)
                        {
                            System.out.println(v.getText());
                        }
                        found="true";
                    }
                }
                if(found.matches("true"))
                {
                    break;
                }
            }     
          }
    }

Comments

  1. please check your code it's not working

    ReplyDelete
  2. yes,,,, the code i have written correct only some how there are few words missing , thanks for pointing that.... in the code,,, do the below changes

    List rows=table.findElements(By.tagName("tr"));

    List cols=row.findElements(By.tagName("td"));

    List vals=row.findElements(By.tagName("td"));


    ReplyDelete

Post a Comment