如何结合两个xpath,以便可以根据显示的文本单击编辑图标

时间:2019-09-04 06:24:46

标签: selenium selenium-webdriver xpath

在网格中,我想单击编辑图标,但是基于下一列中的文本,我要单击编辑图标。

为此,我想结合两个xpath。

我已经尝试过使用此xpath

/tbody/tr/td[1]/a/following-sibling:://td[contains(text(),'m/s macro power contactors')]

下面是我的HTML代码

<tbody>
  <tr role="row" class="odd">…</tr>
  <tr role="row" class="even">…</tr>
  <tr role="row" class="odd">…</tr>
  <tr role="row" class="even">…</tr>
  <tr role="row" class="odd">
    <td class="sorting_1">
      <a style="color:red;" title="Clike here to Edit"href="javascript:EditClick(3779)" class="ace-icon fa fa-pencil bigger-130 green">…</a>
    </td>
    <td>m/s macro power contactors</td>
    <td>LC0063</td>
    <td>Local</td>
    <td></td>
  </tr>
  <tr role="row" class="even">…</tr>
  <tr role="row" class="odd">…</tr>

每一行都有一个编辑图标,我可以轻松地在编辑图标上单击而没有困难

我期望的是基于此“ m / s宏电源接触器”的,我想点击此图标。

1 个答案:

答案 0 :(得分:0)

您需要先从文本开始,然后逐步向上处理html树

//td[.='m/s macro power contactors']/preceding-sibling::td/a