假设我在页面上有一些这样的标题
<h1 class="head-1"> Title 1 </h1>
<h2 class="head-2"> title 2 </h2>
<h3 class="head-3"> title 2.1 </h3>
<h3 class="head-3"> title 2.2 </h3>
<h2 class="head-2"> title 3 </h2>
<h3 class="head-3"> title 3.1</h3>
<h3 class="head-3"> title 3.2</h3>
假设我使用 //h3[text()= "title 3.2"]
找到了元素.
现在,我想获取当前标题的 super 元素。
例如我想做类似 headingElement.getSuperHeading();//this method will have code to find the super heading
的事情
有人知道如何从当前元素中检索 super 标题元素吗?
最佳答案
您可以使用 xpath 轴 https://www.w3schools.com/xml/xpath_axes.asp
试试这个
//h3[text()= "标题3.2"]/parent::*
关于java - 如何识别当前标题的 super (父)标题级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61317214/