<flow-end-node _nghost-c50="" id="T000k2d27hnb" class="jtk-draggable jtk-droppable ng-star-inserted jtk-endpoint-anchor jtk-connected xh-highlight" style="top: 160px; left: 592px; z-index: 102;">
<div _ngcontent-c50="" class="invisible-node-holder node-setup">
<div _ngcontent-c50="" class="node-anchor left target"></div>
<button _ngcontent-c50="" class="mat-fab" mat-fab="" style="background: rgb(66, 189, 65);"><span class="mat-button-wrapper">
<mat-icon _ngcontent-c50="" class="mat-icon material-icons" role="img" aria-hidden="true">done</mat-icon>
<flow-notification-icon _ngcontent-c50="" _nghost-c48="">
<!---->
</flow-notification-icon>
</span><div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div><div class="mat-button-focus-overlay"></div></button>
<label _ngcontent-c50="">End (success)</label>
</div></flow-end-node>
<flow-end-node _nghost-c50="" id="T000k2d27hnc" class="jtk-draggable jtk-droppable ng-star-inserted jtk-endpoint-anchor jtk-connected xh-highlight" style="top: 368px; left: 816px; z-index: 103;">
<div _ngcontent-c50="" class="invisible-node-holder node-setup">
<div _ngcontent-c50="" class="node-anchor left target"></div>
<button _ngcontent-c50="" class="mat-fab" mat-fab="" style="background: rgb(230, 42, 16);"><span class="mat-button-wrapper">
<mat-icon _ngcontent-c50="" class="mat-icon material-icons" role="img" aria-hidden="true">clear</mat-icon>
<flow-notification-icon _ngcontent-c50="" _nghost-c48="">
<!---->
</flow-notification-icon>
</span><div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div><div class="mat-button-focus-overlay"></div></button>
<label _ngcontent-c50="">End (failure)</label>
</div></flow-end-node>
网页中有上述元素,我想获取带有文本“结束(成功)”标签的流结束节点。我已经尝试了以下两种方法,想了解为什么第一种方法不起作用。
//flow-end-node[//label[text()='End (success)']]
(这个给了我两个节点)//label[text()='End (success)']/ancestor::flow-end-node
(这工作正常)
最佳答案
您的第一个 XPath 选择两个节点,因为文档中有两个 flow-end-nodes
。您的谓词仅检查文档中任何位置是否存在标签
,而不是flow-end-node<的后代
.
要更正,请从绝对 //label
更改,
//flow-end-node[//label[text()='End (success)']]
相对于.//标签
,
//flow-end-node[.//label[text()='End (success)']]
然后,正如预期的那样,只会选择一个flow-end-node
。
关于html - 为什么我的 XPath 忽略谓词并选择多个节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51228923/