gpt4 book ai didi

selenium - 获取父级的 xpath

转载 作者:行者123 更新时间:2023-12-02 11:19:11 26 4
gpt4 key购买 nike

我是 xpath 的新手,我有一个像这样的 html 结构:

 <div _ngcontent-c7="" class="new-dash hvr-fade ng-star-inserted" tabindex="0" ng-reflect-router-link="//service-aaaa" id="app109">
<h5 _ngcontent-c7="" class="parent-highlight">
<a _ngcontent-c7="" class="parent-highlight">
<!--bindings={
"ng-reflect-ng-if": "false"
}--><br _ngcontent-c7="">
</a>
<img _ngcontent-c7="" alt="AppIcon" class="icon-active" width="65px" id="appIcon10" src="../assets/images/service_category_active.svg">
<h5 _ngcontent-c7="" class="parent-highlight top-20 new-label" id="appNameText10">Service1234</h5>
</h5>
</div>

我想选择具有h5.text=Service1234的父div

请帮忙。

最佳答案

//h5[text()="Service1234"]/ancestor::div[1]

读取:找到“h5”元素,按相反顺序找到其所有祖先“div”-s(最接近的第一个),然后返回第一个。

关于selenium - 获取父级的 xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54490520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com