英文:
How to find xpath of a parent div based on multiple children divs?
问题
考虑以下示例HTML:
<div class="randomclass-parent" id="需要找到这个div"> // 我要找的父div
<table class="rando table">
<tbody role="presentation">
<tr role="presentation">
<td id="radnom">
<div class="childclass">Sam</div>
<td id="radnom">
<div class="childclass">Elliot</div>
<td id="radnom">
<div class="childclass">Smith</div>
</tbody>
</table>
</div>
现在,我知道父div包含一个table
,其中包含多个表格行,这些行又包含带有预先知道的一些文本的表格数据标签。我想要能够像这样做。不确定其语法是什么。
String xpathofParentDiv = "父div,其中包含"//div[contains(text(),'Sam')] and //div[contains(text(),'Elliot')] 和 //div[contains(text(),'Smith')]";
我该如何根据位于表格数据<td>
内的子div的文本来定位父div呢?
英文:
Consider this html for example
<div class="randomclass-parent" id="Need to find this div"> // Parent Div I am looking for
<table class="rando table">
<tbody role="presentation">
<tr role="presentation">
<td id="radnom">
<div class="childclass">Sam</div>
<td id="radnom">
<div class="childclass">Elliot</div>
<td id="radnom">
<div class="childclass">Smith</div>
</tbody>
</table>
</div>
Now, I know that the parent div contains a table
which contains multiple table rows, which in turn contain table data tag, which contains the div with some text that I know beforehand. I want to be able to do something like this. Not sure what is the syntax for it.
String xpathofParentDiv=Parent div which contains "//div[contains(text(),'Sam')] and //div[contains(text(),'Elliot')] and //div[contains(text(),'Smith')]";
How do i go about locating the parent div, based on the text in the children divs located inside the table data <td>
答案1
得分: 1
使用以下 xpath
//div[.//div[text()='Sam'] 和 .//div[text()='Elliot'] 和 .//div[text()='Smith']]
英文:
Use the following xpath
//div[.//div[text()='Sam'] and .//div[text()='Elliot'] and .//div[text()='Smith']]
答案2
得分: 0
Parent是一个用于获取当前节点的父节点的方法。
我希望这是你要找的内容-
Xpath= //*[text()='Sam']//parent::div
英文:
Parent is a method used to retrieve the parent node of the current node
I hope this is what you lookin for-
Xpath= //*[text()='Sam']//parent::div
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论