gpt4 book ai didi

xpath - 如何使用 xpath 选择相邻的 html 元素?

转载 作者:行者123 更新时间:2023-12-02 03:20:42 25 4
gpt4 key购买 nike

我有一个html源码,里面有几个输入框定义如下:

<div class="jupyter-widgets widget-hbox widget-text" style="">
<div class="widget-label" style="display: block;">Project:</div>
<input type="text" class="form-control" placeholder="">
</div>
<div class="jupyter-widgets widget-hbox widget-text" style="">
<div class="widget-label" style="display: block;">Title:</div>
<input type="text" class="form-control" placeholder="">
</div>
...

如何选择与 Project 元素关联的 input 元素?

最佳答案

这应该有效:

//div[contains(text(), "Project")]/following-sibling::input

第一部分 //div[contains(text(), "Project")] 将找到在文本属性中具有“Project”的 div 元素,然后是 /following-sibling: :input 将找到该 div 元素的输入类型兄弟。

阅读有关这些 xpath 函数 here 的更多信息。

关于xpath - 如何使用 xpath 选择相邻的 html 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54901655/

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