I am trying to print all the column values from a table based on a parameter. If the paramter matches then all the column values should be printed. This is not happening in my code below.
public class DynamicTableHandling extends DriverFactory {
static String company = "ABB India Ltd.";
public static void main(String[] args) {
init_driver("chrome");
driver.get("https://money.rediff.com/sectors/bse/power");
extractTableValues(company);
}
public static void extractTableValues(String company) {
//print all the column values from the table when the company name provided has matched//
List<WebElement> tableRow = driver.findElements(By.xpath("//table[@class='dataTable']/tbody/tr"));
for (int row = 0; row < tableRow.size(); row++) {
WebElement colData = tableRow.get(row);
List<WebElement> tableCol = colData.findElements(By.tagName("td"));
for (int col = 0; col < tableCol.size(); col++) {
String result = tableCol.get(col).getText();
if (company.equals(result.trim())) {
System.out.print(result + " | ");
break;
}
}
}
}
}
Output -- ABB India Ltd. |