I want to find specific row in a mat-table, and I want to click a specific mat-icon. However I don't know how to use xpath in the case of mat-icon. My code is find the table, and iterate over the rows to find specific row. After that it should click on mat-icon in the last column. Maybe can I find it by its name? Here is my code:
public void clickIconFromSelectedRow(String text, String icon) {
WebElement baseTable = driver.findElement(By.xpath("//mat-table[@role='table']"));
List<WebElement> tableRows = baseTable.findElements(By.xpath("//mat-row[@role='row']"));
for (WebElement row : tableRows){
List<WebElement> cols = row.findElements(By.xpath("//mat-cell[@role='cell']"));
for (WebElement col : cols) {
if (col.getText().equals(text)) {
driver.findElement(By.xpath("SOME XPATH AND + text + TEXT")).click();
}
}
}
}
Here is the HTML for your information
Note: in the last column, there must be several mat-icons.