Xpath 根据TH和TR选择输入字段
我在下一张桌子上有TH:Xpath 根据TH和TR选择输入字段,xpath,Xpath,我在下一张桌子上有TH: <table cellspacing="1" border="1" id="FinancialsGrid"> <thead> <tr> <th>Product</th> <th>Slice</th> <th>Units</th> <th&g
<table cellspacing="1" border="1" id="FinancialsGrid">
<thead>
<tr>
<th>Product</th>
<th>Slice</th>
<th>Units</th>
<th>Accrual Rate</th>
<th>Trend Factor</th>
<th>Base Units</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3">Lorem Ipsum</td>
<td>Previous</td>
<td>6,866</td>
<td>0.00 %</td>
<td>0.00 %</td>
<td>6,866</td>
</tr>
<tr>
<td>Current</td>
<td>6,866</td>
<td>0.00 %</td>
<td>0.00 %</td>
<td>6,866</td>
</tr>
<tr>
<td>Proposed</td>
<td>6,866</td>
<td><input type="text" style="width:60px;" value="0.00 %"></td>
<td style="width:60px;"><input type="text" style="width:60px;" value="0.00 %"></td>
<td style="width:60px;"><input type="text" style="width:90px;" value="6,866"></td>
</tr>
</tbody>
</table>
表视图:
下面是XPath
(//table[@id='FinancialsGrid']//input)[count(//tr/th)-index-of(//tr/th, //tr/th[text()='Trend Factor']) + 1]
或者另一个没有index-of()的函数(用于Firebug):
将获取所需的输入节点,其中:
count(//tr/th) is count of columns
index-of(//tr/th, //tr/th[text()='Trend Factor']) - current number of column
(//table[@id='FinancialsGrid']//input) - sequence of input nodes.
因此,我们从序列中计算输入节点和除根节点的位置。
首先,看起来你的脑袋里有6列,最后两行有5列。是的,没错。我提供了正确的变体。Lorem Ipsum类似于一个general.column/row编号,哪一个可以修复,哪一个可以更改?若行数是固定的,那个么需要按原样转到N:th elementI提供的表结构。它无法改变。不幸的是,结构无法改变。这是设计好的。需要根据当前表结构为输入创建xpath。@dan silver,是的,缺少属性rowspan=3-更新了表的xpath。在FireBug中显示无效xpath FireBug不知道xpath函数索引-of()-只需使用simple count()函数解决它,但找到了另一列(th)的输入。
(//table[@id='FinancialsGrid']//input)[count(//tr/th)-count(//tr/th[text()='Trend Factor']/preceding-sibling::*)]
count(//tr/th) is count of columns
index-of(//tr/th, //tr/th[text()='Trend Factor']) - current number of column
(//table[@id='FinancialsGrid']//input) - sequence of input nodes.