I desing a script to print all cell text Below is code for same .It show me error
java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
How Can i avoid this exception error ?
public class WebTableClass
{
WebDriver driver;
String path = System.getProperty("user.dir");
public void openbrower()
{
System.setProperty("webdriver.chrome.driver",path+ "//Browser//chromedriver.exe");
driver = new ChromeDriver();
driver.get("
http://only-testing-blog.blogspot.in/2014/05/form.html");
}
public void webtable()
{
/*First Locate table on which we have to perform action
tbody =table body*/
WebElement table = driver.findElement(By.xpath(("(//tbody)[position()=1]")));
/*Now get all rows of selected table
* tr =table row*/
List<WebElement> table_row =table.findElements(By.tagName("tr"));
/*Now get all rows count of table*/
int table_row_count = table_row.size();
/*this loop execute till all row count*/
try {
for (int row =1; row<table_row.size(); row++)
{
/*now get table cell(table column) of table*/
List<WebElement> table_cell =table.findElements(By.tagName("td"));
int table_cell_count =table_cell.size();
System.out.println("table row " +table_row_count + "table column" +table_cell_count);
for (int cell =1;cell <table_cell.size(); cell++)
{
/*not get text from particular column cell*/
String table_cell_text =table_row.get(cell).getText();
System.out.println("Cell Value Of row number "+row+" and column number "+cell+" Is " +table_cell_text);
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
public static void main (String args[])
{
WebTableClass table_object =new WebTableClass();
table_object.openbrower();
table_object.webtable();
}
}