/** *<b>Name:</b> WebTable</br><b>Description: </b>This class is used to handling * web table</br> * * */
public class WebTable {
private WebElement webTable; StartingSelenium ss = new StartingSelenium();
public WebTable(WebElement webTable) { this.webTable = webTable; }
public WebElement getWebTable() { return webTable; }
/** *<b>Name: getTableRows</b><b>Description:</b> This method is to get table * rows list * *@return tableRows */ private List<WebElement> getTableRows() { List<WebElement> tableRows = webTable.findElements(By.tagName("tr")); return tableRows; }
/** *<b>Name: getTableColumns</b><b>Description:</b> This method is to get * table columns list * *@param currentRow * *@return tableColumns */ private List<WebElement> getTableColumns(WebElement currentRow) { List<WebElement> tableColumns = currentRow.findElements(By .tagName("td")); return tableColumns; }
/** *<b>Name: getRowCount</b><b>Description:</b> This method is to get the * table row count * *@return rowCount */ public int getRowCount() { int rowCount = getTableRows().size(); Reporter.log("Rows in the table: " + rowCount, true); return rowCount; }
/** *<b>Name: getColumnCount</b><b>Description:</b> This method is to get the * table column count * *@return columnCount */ public int getColumnCount() { WebElement headerRow = getTableRows().get(0); List<WebElement> tableColumns = getTableColumns(headerRow); int columnCount = tableColumns.size(); Reporter.log("Column in the table: " + columnCount, true); return columnCount; }
/** *<b>Name: getCellText</b><b>Description: </b> This method is to get the * specific cell data * *@param row *@param column *@return cellText */ public String getCellText(int row, int column) { WebElement currentRow = getTableRows().get(row); List<WebElement> tableColumns = getTableColumns(currentRow); return tableColumns.get(column).getText(); }
/** *<b>Name: getRowByCellText</b><b>Description:</b> This method is to get * the row number by the cell data * *@param cellText * *@return rowNumber */ public int getRowByCellText(String cellText) { int rowCount = getRowCount(); int colCount = getColumnCount(); int getRow = 0; boolean flag;
for (int i = 0; i < rowCount; i++) { flag = false;
for (int j = 0; j < colCount; j++) { if (getCellText(i, j).equals(cellText)) { getRow = i; flag = true; Reporter.log("The text: " + cellText + " in row number: " + getRow, true); break; } } if (flag) { break; } } return getRow; }
/** * <b>Name: clickLinkInCell</b><b>Description: </b> This method is to click * link in the specific cell * *@param row *@param column *@param index * */ public void clickLinkInCell(int row, int column, int index) { WebElement currentRow = getTableRows().get(row); WebElement currentCell = getTableColumns(currentRow).get(column); currentCell.findElements(By.tagName("a")).get(index).click(); Reporter.log("Clickin a link on the row: " + row, true); }
/** *<b>Name: clickLinkInCell</b><b>Description: </b> This method is to click * link in the specific cell * *@param row *@param column *@param index *@param linkName * */ public void clickLinkInCell(int row, int column, int index, String linkName) { WebElement currentRow = getTableRows().get(row); WebElement currentCell = getTableColumns(currentRow).get(column); WebElement we = currentCell.findElements(By.tagName("a")).get(index); ss.clickUsingJS(we, linkName); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } }
近期评论