public string GetValueOfCellForRecordWithTitle(string recordTitle, string recordType, string cell) { var records = Element.FindElements(By.CssSelector(GridLocators.GridRow)); var recordsCount = Element.FindElements(By.CssSelector(GridLocators.TitleColumnLocator)).Where(d => d.Text.Equals(recordTitle)).ToArray().Length; if (recordsCount == 0) { throw new WebDriverException(recordType + ": " + recordTitle + " Not Found in " + recordType + " Grid. Unable to get requested value."); } if (recordsCount > 1) { throw new WebDriverException("More than one record with the title " + recordTitle + " found on the " + recordType + " grid. Found " + recordsCount + " records. Unable to determin which record was requested."); } foreach (var record in records) { if (record.FindElement(By.CssSelector(GridLocators.TitleColumnLocator)).Text.Equals(recordTitle)) { var cellToGet = record.FindElements(By.CssSelector(GridLocators.GridCellSelector(cell))); if (cellToGet.Count != 1) { throw new WebDriverException("Cell to get not found or more than one option found, looking for cell " + cell + ". Found " + cellToGet.Count + "."); } return(cellToGet[0].Text); } } throw new WebDriverException("Failed to get cell value on the grid, method exited unexpectedly."); }
public void ClickOnCellofRecordWithTitle(string recordTitle, string recordType, string cellToClick) { var records = Element.FindElements(By.CssSelector(GridLocators.GridRow)); var recordsCount = Element.FindElements(By.CssSelector(GridLocators.TitleColumnLocator)).Where(d => d.Text.Equals(recordTitle)).ToArray().Length; if (recordsCount == 0) { throw new WebDriverException(recordType + ": " + recordTitle + " Not Found in " + recordType + " Grid. Unable to click on requested cell."); } if (recordsCount > 1) { throw new WebDriverException("More than one record with the title " + recordTitle + " found on the " + recordType + " grid. Found " + recordsCount + " records. Unable to determin which record requested."); } foreach (var record in records) { if (record.FindElement(By.CssSelector(GridLocators.TitleColumnLocator)).Text.Equals(recordTitle)) { var itemToClick = record.FindElements(By.CssSelector(GridLocators.GridCellSelector(cellToClick))); if (itemToClick.Count != 1) { throw new WebDriverException("Cell to click not found or more than one option found, looking for cell " + cellToClick + ". Found " + itemToClick.Count + "."); } itemToClick[0].Click(); break; } } }