我正在尝试遍历 HTML 表以从中获取值,但我没有得到想要的结果。这是 HTML 代码:<div class="o_sale_order table-responsive"> <table class="o_list_view table table-sm table-hover table-striped o_list_view_ungrouped"> <thead> <tr> <th width="1" class="o_list_record_selector"> <div class="custom-control custom-checkbox"> <input type="checkbox" id="checkbox-868" class="custom-control-input"> <label for="checkbox-868" class="custom-control-label"></label></div> </th> <th class="o_column_sortable" data-original-title="" title="">Quotation Number</th> <th class="o_column_sortable" data-original-title="" title="">Quotation Date</th> <th class="o_column_sortable" data-original-title="" title="">Customer</th> <th class="o_column_sortable" data-original-title="" title="">Salesperson</th> <th class="o_column_sortable" style="text-align: right;" data-original-title="" title="">Total</th> <th class="o_column_sortable" data-original-title="" title="">Status</th> </tr> </thead> <tbody class="ui-sortable"> <tr class="o_data_row"> <td width="1" class="o_list_record_selector"> <div class="custom-control custom-checkbox"> <input type="checkbox" id="checkbox-869" class="custom-control-input"> <label for="checkbox-869" class="custom-control-label"></label></div> </td> <td class="o_data_cell o_readonly_modifier o_required_modifier">SO107</td> <td class="o_data_cell o_required_modifier">03/04/2019 17:40:46</td> <td class="o_data_cell o_required_modifier">AA</td> <td class="o_data_cell">Administrator</td> <td class="o_data_cell o_list_number o_monetary_cell o_readonly_modifier"> <span class="o_field_monetary o_field_number o_field_widget o_readonly_modifier" name="amount_total">305.00 €</span></td> <td class="o_data_cell o_readonly_modifier">Quotation Sent</td> </tr>
2 回答
侃侃尔雅
TA贡献1801条经验 获得超16个赞
您可以直接在内部的第一列中找到所有表格单元格SOxxx。
List<WebElement> first_cloumns = driver.findElements(
By.cssSelector("div.o_sale_order tbody td:nth-child(1)"));
List<String> values = first_cloumns
.stream() // require JDK 8 and higher
.map(td -> td.getText())
.collect(Collectors.toList());
当年话下
TA贡献1890条经验 获得超9个赞
试试这个 xpath。它将返回所有包含 SO 值的单元格
By.xpath("//table//td[contains(text(),'SO')]");
List<WebElement> rows = driver.findElements(By.xpath("//table//td[contains(text(),'SO')]"));
添加回答
举报
0/150
提交
取消