Trying to loop through a grid and find the cell, which is a div, for the row / column:
PL-Planning documentation
Duration
What’s wrong with keyword? How does one do this?
– I tried quite a few times to upload more images but I keep getting errors.
String planning = 'PL-Planning documentation'
String duration = 'Duration'
CustomKeywords.'reusableComponents.webTable.ClickElementPropertyByTextIdentifierAndColName'('grid1', planning, duration)
@Keyword
public void ClickElementPropertyByTextIdentifierAndColName(String tableCalssName, String RowTextIdentifier, String ColumnName){
int columnIndex = 0;
WebUI.verifyTextPresent(RowTextIdentifier, false, FailureHandling.OPTIONAL)
// driver obj.
WebDriver driver = DriverFactory.getWebDriver()
//locate table'
WebElement Table = driver.findElement(By.className(tableCalssName.trim()))
//To locate rows of table it will Capture all the rows available in the table '
List<WebElement> Rows = Table.findElements(By.tagName('span'))
//print row counts
println('No. of rows: ' + Rows.size())
////Loop will execute for all the rows of the table'
table: for (int i = 0; i < Rows.size(); i++) {
//To locate columns(cells) of that specific row'
List<WebElement> Cols = Rows.get(i).findElements(By.tagName('span'))
// for each column in a row
for (int j = 0; j < Cols.size(); j++) {
println (Cols.get(j).getText())
if (Cols.get(j).getText().equalsIgnoreCase(ColumnName)) {
columnIndex = j;
}
//Verifying the expected text in the each cell'
if (Cols.get(j).getText().equalsIgnoreCase(RowTextIdentifier)) {
// click on link in a row if row name matches
Cols.get(columnIndex).findElement(By.tagName('div')).click()
break table
}
}
}
}
Grid Image
Row HTML