Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
i wrote the code for the getting the text from the all the rows and columns
package WebTable_Handling;

import java.util.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.chrome.ChromeDriver;

public class Webtable_operations {
public static WebDriver driver;

public static void main(String[] args) {
// finding the totoal no. of rows
System.setProperty("webdriver.chrome.driver", "./exe files/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("file:///E:/Tushar/NCSM8.html");

List<webelement> rows = driver.findElements(By.xpath("//table[@name='Num']//tr['+']"));
int rowcount = rows.size();
System.out.println(rowcount);


//finding the numbers of columns in the webtable
List<webelement> columns = driver.findElements(By.xpath("//table[@name='Num']//tr['i+']/td"));
int column_count = columns.size();
System.out.println(column_count);



//getting the data from the webtables
for(int i=0;i<=rowcount;i++)
{
//WebElement wb = columns.get(i);
String data = rows.get(i).getText();
System.out.println(data);

}





}

}
it is giving me exceptions like arrayindexof bounds

What I have tried:

i have tried:
for(int i=0;i<rowcount;i++)
		{
			//WebElement wb = columns.get(i);
			String data = rows.get(i).getText();
			System.out.println(data);
			
		}
Posted
Comments
summiya1 12-Oct-18 12:11pm    
try this

for(int i=0;i<rows.size();i++)
		{
			String data = rows.get(i).getText();
			System.out.println(data);
			
		}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900