Я печатаю некоторое содержимое веб-таблицы, когда я печатаю содержимое, выводимое ниже. (веб-драйвер crome xp)
Код:
WebDriver driver = DriverFactory.getWebDriver()
// simplified: find table which contains the keyword
WebElement tableElement = driver.findElement(By.xpath("/html/body/div[4]/div/main/div/div[3]/div[2]/div/div[1]/div[4]/div[2]/table"));
// create empty table object and iterate through all rows of the found table element
ArrayList<HashMap<String, WebElement>> userTable = new ArrayList<HashMap<String, WebElement>>();
ArrayList<WebElement> rowElements = tableElement.findElements(By.xpath(".//tr"));
// get column names of table from table headers
ArrayList<String> columnNames = new ArrayList<String>();
ArrayList<WebElement> headerElements = rowElements.get(0).findElements(By.xpath(".//th"));
for (WebElement headerElement: headerElements) {
columnNames.add(headerElement.getText());
}
// iterate through all rows and add their content to table array
for (WebElement rowElement: rowElements) {
HashMap<String, WebElement> row = new HashMap<String, WebElement>();
// add table cells to current row
int columnIndex = 0;
ArrayList<WebElement> cellElements = rowElement.findElements(By.xpath(".//td"));
for (WebElement cellElement: cellElements) {
row.put(columnNames.get(columnIndex), cellElement);
columnIndex++;
}
userTable.add(row);
println userTable
}
вывод 