如何在硒的单个xpath中获取多个值

时间:2018-09-10 10:49:16

标签: selenium-webdriver xpath

我被困在创建TR标记下的xpath和 我想从每个TR标签获取td [2],td [3],td [4]和td [5]的值。参见下面的HTML。

<tbody>
   <tr role="row" class="odd">
      <td><img src="/Content/Uploaded//Profile//MasterAdmin/ashishadmin/95.jpg" class="profilepic img-responsive img-circle"></td>
      <td>Ashish A Admin</td>
      <td>ashishad@mailinator.com</td>
      <td></td>
      <td>ashishadmin</td>
      <td><label class="chkcontainer pointer-none"><input type="checkbox" class="chk" checked="checked"><span class="checkmark"></span> </label></td>
      <td><i class="fa fa-circle text-warning"></i></td>
      <td><a href="/Admin/Admin/SaveMasterAdmin/47" class="btn btn-success m-l-5">Edit</a><a href="#" class="btn delete btn-danger m-l-5" onclick="DeleteData(this,47);">Delete</a></td>
   </tr>

   <tr role="row" class="even">
      <td><img src="/Content/Uploaded//Profile//MasterAdmin/shpatel/download.jpg" class="profilepic img-responsive img-circle"></td>
      <td>Shree A Patel</td>
      <td>shpatel@mailinator.com</td>
      <td>8767676766</td>
      <td>shpatel</td>
      <td><label class="chkcontainer pointer-none"><input type="checkbox" class="chk" checked="checked"><span class="checkmark"></span> </label></td>
      <td><i class="fa fa-circle text-warning"></i></td>
      <td><a href="/Admin/Admin/SaveMasterAdmin/31" class="btn btn-success m-l-5">Edit</a><a href="#" class="btn delete btn-danger m-l-5" onclick="DeleteData(this,31);">Delete</a></td>
   </tr>

   <tr role="row" class="odd">
      <td><img src="/content/custom/img/default-user.jpg" class="profilepic img-responsive img-circle"></td>
      <td>Ashish G Savaliya</td>
      <td>ashish@mailinator.com</td>
      <td>7897897890</td>
      <td>asavaliya</td>
      <td><label class="chkcontainer pointer-none"><input type="checkbox" class="chk" checked="checked"><span class="checkmark"></span> </label></td>
      <td><i class="fa fa-circle text-warning"></i></td>
      <td><a href="/Admin/Admin/SaveMasterAdmin/32" class="btn btn-success m-l-5">Edit</a><a href="#" class="btn delete btn-danger m-l-5" onclick="DeleteData(this,32);">Delete</a></td>
   </tr>
</tbody>

要创建每行仅有2、3、4和5个TD值的xpath。参见下图,我想使用xpath打印所有必需的数据。

enter image description here

1 个答案:

答案 0 :(得分:1)

//tr/td[position() >= 2 and position() <= 5]