I'm trying to read an HTML table and get all the values into a 2d list using selenium. I'm using streamable to create a List inside another map()
method. But I get Cannot cast from List<Functions.Function1<Object,String>> to List<String>
error at nested collect
method's line
HTML:
+--------+-------+
| r1 v1 | r1 v2 |
+--------+-------+
| r2 v1 | r2 v2 |
+--------+-------+
<html>
<body>
<table>
<tbody>
<tr>
<td>
<div>
<span>r1 v1</span>
</div>
</td>
<td>
<div>
<span>r1 v2</span>
</div>
</td>
</tr>
<tr>
<td>
<div>
<span>r2 v1</span>
</div>
</td>
<td>
<div>
<span>r2 v2</span>
</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Java Code:
public List getTableData() {
return webElement
.findElements(By.xpath(".//table/tbody/tr"))
.stream()
.map(row -> {
return row
.findElements(By.xpath(".//td/div/span"))
.stream()
.map(cell -> {
return cell
.getAttribute("innerText");
})
.collect(Collectors.toList()); // : Cannot cast from List<Functions.Function1<Object,String>> to List<String>
})
.collect(Collectors.toList());
}
Why am I gettting this error? How can I create a 2d List out of this table using java streamable?