'''''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;
}
}
}
}
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
for(WebElement row : rows)
{
List
for(WebElement col : cols)
{
str=col.getText().trim();
if(str.matches("ABB"))
{
List
for(WebElement v:vals)
{
System.out.println(v.getText());
}
found="true";
}
}
if(found.matches("true"))
{
break;
}
}
}
}
good
ReplyDeleteplease check your code it's not working
ReplyDeleteyes,,,, 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
ReplyDeleteList rows=table.findElements(By.tagName("tr"));
List cols=row.findElements(By.tagName("td"));
List vals=row.findElements(By.tagName("td"));