我怎么能选择一个表标题有相同的类名,而不是任何其他唯一的属性在web驱动程序

How can I select a table heading which have same class name and not any other unique attribute in web driver

本文关键字:任何 其他 web 驱动程序 属性 唯一 选择 一个 标题 怎么能      更新时间:2023-09-26
<th id="desc" class="sort" data="aWQ=">S.No</th>
<th class="table_head" data="bmFtZQ==">Customer</th>
<th class="table_head" data="c3R5bGVfbm8=">Style#</th>
<th class="table_head" data="c3R5bGVfZGVzYw==">Style Description</th>
<th class="table_head" data="ZmFicmljX2Rlc2M=">Fabric Description</th>
<th class="table_head" data="YXBwcm92ZWQ=">Status</th>
<th>Action </th>

able代码为所有列声明相同的类名,ID &CLASS仅在用户选择要过滤的列时分配。在这种情况下,我如何选择所有的列

使用jQuery可以这样做:

$('th').eq(1) // the "customer" element
$('th').eq(4) // the "fabric description" element
在普通JS中,

就像这样简单:

document.querySelectorAll('th')[1] // the "customer" element
document.querySelectorAll('th')[4] // the "fabric description" element

有了这个,您可以很容易地选择第n个表列,但是您必须事先知道该列的索引。