gpt4 book ai didi

java - 使用 Selenium/Katalon 迭代 html 表

转载 作者:太空宇宙 更新时间:2023-11-04 09:49:04 24 4
gpt4 key购买 nike

我正在尝试迭代 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&nbsp;€</span></td>
<td class="o_data_cell o_readonly_modifier">Quotation Sent</td>
</tr>
<tr class="o_data_row">
<td width="1" class="o_list_record_selector">
<div class="custom-control custom-checkbox">
<input type="checkbox" id="checkbox-870" class="custom-control-input">
<label for="checkbox-870" class="custom-control-label">​</label></div>
</td>
<td class="o_data_cell o_required_modifier">SO055</td>
<td class="o_data_cell o_required_modifier">03/01/2019 20:24:35</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">2.44&nbsp;€</span></td>
<td class="o_data_cell o_readonly_modifier">Quotation</td>
</tr>
<tr class="o_data_row">
<td width="1" class="o_list_record_selector">
<div class="custom-control custom-checkbox"><input type="checkbox" id="checkbox-871" class="custom-control-input">
<label for="checkbox-871" class="custom-control-label">​</label></div>
</td>
<td class="o_data_cell o_required_modifier">SO039</td>
<td class="o_data_cell o_required_modifier">03/01/2019 12:16:08</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">2.44&nbsp;€</span></td>
<td class="o_data_cell o_readonly_modifier">Quotation</td>
</tr>
<tr class="o_data_row">
<td width="1" class="o_list_record_selector">
<div class="custom-control custom-checkbox">
<input type="checkbox" id="checkbox-872" class="custom-control-input">
<label for="checkbox-872" class="custom-control-label">​</label></div>
</td>
<td class="o_data_cell o_required_modifier">SO025</td>
<td class="o_data_cell o_required_modifier">02/28/2019 19:50:59</td>
<td class="o_data_cell o_required_modifier">BB</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">2.44&nbsp;€</span></td>
<td class="o_data_cell o_readonly_modifier">Quotation</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td class="name"></td>
<td class="date_order"></td>
<td class="partner_id"></td>
<td class="user_id"></td>
<td class="amount_total o_list_number" title="Total Tax Included">312.32</td>
<td class="state"></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</main>
</div>

我需要从每一行获取以“SO”开头的值,如下所示:

<td class="o_data_cell o_required_modifier">SO055</td>

我尝试过:

List<String> list = new ArrayList<>();
driver.findElement(By.xpath("//*[@class = 'o_dropdown_toggler_btn btn btn-secondary dropdown-toggle' and (contains(text(), 'Filters') or contains(., 'Filters'))]")).click();
driver.findElement(By.xpath("(//a[contains(text(),'Quotations')])[2]")).click();
driver.findElement(By.xpath("//*[@class = 'o_dropdown_toggler_btn btn btn-secondary dropdown-toggle' and (contains(text(), 'Filters') or contains(., 'Filters'))]")).click();

List<WebElement> rows = driver.findElements(By.xpath("//table[@class='o_list_view table table-sm table-hover table-striped o_list_view_ungrouped']//tr[not(th)]"));
Iterator<WebElement> iter = rows.iterator();
while(iter.hasNext()) {
WebElement tr = iter.next();
WebElement td = tr.findElement(By.xpath("./td[(@class='o_data_cell o_readonly_modifier o_required_modifier')]"));
listaPreventiviFatturabili.add(td.getText());
}

但它不起作用。

这是相关网页的屏幕截图:

Screen

你能帮我吗?

另一个问题:选择“引用”过滤器后如何等待页面加载?

最佳答案

试试这个 xpath。它将返回包含 SO 值的所有单元格

By.xpath("//table//td[contains(text(),'SO')]");

List<WebElement> rows = driver.findElements(By.xpath("//table//td[contains(text(),'SO')]"));

关于java - 使用 Selenium/Katalon 迭代 html 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55022951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com