public List<Map<Object, String>> getRows() { List<Map<Object, String>> results = new ArrayList<Map<Object, String>>(); List<String> headings = getHeadings(); List<WebElement> rows = getRowElementsFor(headings); for (WebElement row : rows) { List<WebElement> cells = cellsIn(row); if (enoughCellsFor(headings).in(cells)) { results.add(rowDataFrom(cells, headings)); } } return results; }
public static List<WebElement> filterRows(final WebElement table, final BeanMatcher... matchers) { return new HtmlTable(table).getRowElementsWhere(matchers); }
public List<WebElement> getRowElements() { return getRowElementsFor(getHeadings()); }
private List<Integer> findMatchingIndexesFor(List<WebElement> rowElements, BeanMatcher[] matchers) { List<Integer> indexes = new ArrayList<Integer>(); List<String> headings = getHeadings(); int index = 0; for(WebElement row : rowElements) { List<WebElement> cells = cellsIn(row); Map<Object, String> rowData = rowDataFrom(cells, headings); if (matches(rowData, matchers)) { indexes.add(index); } index++; } return indexes; }
public List<WebElement> getRowElementsWhere(BeanMatcher... matchers) { List<WebElement> rowElements = getRowElementsFor(getHeadings()); List<Integer> matchingRowIndexes = findMatchingIndexesFor(rowElements, matchers); List<WebElement> matchingElements = new ArrayList<WebElement>(); for(Integer index : matchingRowIndexes) { matchingElements.add(rowElements.get(index)); } return matchingElements; }
public List<String> getHeadings() { if (headings == null) { List<String> thHeadings = convert(headingElements(), toTextValues()); if (thHeadings.isEmpty()) { headings = convert(firstRowElements(), toTextValues()); } else { headings = thHeadings; } } return headings; }
public boolean containsRowElementsWhere(BeanMatcher... matchers) { List<WebElement> rows = getRowElementsWhere(matchers); return (!rows.isEmpty()); }
public List<String> getHeadings() { if (headings == null) { List<String> thHeadings = headingElements() .stream() .map(this::cellToText) .collect(Collectors.toList()); if (thHeadings.isEmpty()) { headings = firstRowElements() .stream() .map(element -> element.getAttribute("textContent")) .collect(Collectors.toList()); } else { headings = thHeadings; } } return headings; }
public HtmlTable inTable(WebElement table) { return new HtmlTable(table, headings); } }
private Map<Object,String> rowDataFrom(List<WebElement> cells, List<String> headings) { Map<Object,String> rowData = new HashMap<Object, String>(); int column = 0; for (String heading : headings) { String cell = cellValueAt(column++, cells); if (!StringUtils.isEmpty(heading)) { rowData.put(heading, cell); } rowData.put(column, cell); } return rowData; }
private List<Integer> findMatchingIndexesFor(List<WebElement> rowElements, BeanMatcher[] matchers) { List<Integer> indexes = new ArrayList<Integer>(); List<String> headings = getHeadings(); int index = 0; for(WebElement row : rowElements) { List<WebElement> cells = cellsIn(row); Map<Object, String> rowData = rowDataFrom(cells, headings); if (matches(rowData, matchers)) { indexes.add(index); } index++; } return indexes; }
public List<WebElement> getRowElementsWhere(BeanMatcher... matchers) { List<WebElement> rowElements = getRowElementsFor(getHeadings()); List<Integer> matchingRowIndexes = findMatchingIndexesFor(rowElements, matchers); List<WebElement> matchingElements = new ArrayList<WebElement>(); for(Integer index : matchingRowIndexes) { matchingElements.add(rowElements.get(index)); } return matchingElements; }
public List<String> getHeadings() { if (headings == null) { List<String> thHeadings = convert(headingElements(), toTextValues()); if (thHeadings.isEmpty()) { headings = convert(firstRowElements(), toTextValues()); } else { headings = thHeadings; } } return headings; }
public boolean containsRowElementsWhere(BeanMatcher... matchers) { List<WebElement> rows = getRowElementsWhere(matchers); return (!rows.isEmpty()); }
public List<WebElement> getRowElements() { return getRowElementsFor(getHeadings()); }
public HtmlTable inTable(WebElement table) { return new HtmlTable(table, headings); } }
private Map<Object,String> rowDataFrom(List<WebElement> cells, List<String> headings) { Map<Object,String> rowData = new HashMap<>(); int column = 0; for (String heading : headings) { String cell = cellValueAt(column++, cells); if (!StringUtils.isEmpty(heading)) { rowData.put(heading, cell); } rowData.put(column, cell); } return rowData; }
public List<Map<Object, String>> getRows() { List<Map<Object, String>> results = new ArrayList<Map<Object, String>>(); List<String> headings = getHeadings(); List<WebElement> rows = getRowElementsFor(headings); for (WebElement row : rows) { List<WebElement> cells = cellsIn(row); if (enoughCellsFor(headings).in(cells)) { results.add(rowDataFrom(cells, headings)); } } return results; }
private List<Integer> findMatchingIndexesFor(List<WebElement> rowElements, BeanMatcher[] matchers) { List<Integer> indexes = new ArrayList<Integer>(); List<String> headings = getHeadings(); int index = 0; for(WebElement row : rowElements) { List<WebElement> cells = cellsIn(row); Map<Object, String> rowData = rowDataFrom(cells, headings); if (matches(rowData, matchers)) { indexes.add(index); } index++; } return indexes; }