为selenium创建动态xpath

时间:2017-08-29 09:27:49

标签: selenium xpath

你能帮我创建XPATH吗?我想用动态网址删除该项目。这是DOM结构。 'beacon name','Major:22'没有改变。只有href被更改。

<div class="panel panel-default panel-small">
 <div class="panel-heading">
  <h3 class="panel-title">beacon name</h3>
 </div>
 <div class="panel-body">
  <div class="row">
   <div class="col-sm-4 preview-data"> UUID: E4504AB5-309C-41BF-BAC4-C384A9EBE57A </div>
   <div class="col-sm-2 preview-data"> Major: 22 </div>
   <div class="col-sm-2 preview-data"> Minor: 33 </div>
   <div class="col-sm-4">
    <div class="action-btns pull-right">
     <a class="btn btn-default btn-xs" href="/beacons/114/edit?back_to=%2Fbeacons">Edit</a>
     <a class="btn btn-danger btn-xs" data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/beacons/114?back_to=%2Fbeacons">Delete</a>
    </div>
   </div>
  </div>
 </div>
</div>

XPath我试过了:

//a[contains('beacon name',/'Delete')]

1 个答案:

答案 0 :(得分:0)

如果您希望"Delete"匹配"Major: 22"按钮,请尝试

//div[normalize-space()="Major: 22"]/following-sibling::div//a[text()="Delete"]

如果是"beacon name"

//h3[.="beacon name"]/following::a[text()="Delete"]

您也可以尝试使用href属性:

//a[@href="/beacons/114?back_to=%2Fbeacons"]