假设我在页面上有一些这样的标题
<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"]找到了元素。
现在,我想要获取当前标题的超级元素。
例如,我想做一些像headingElement.getSuperHeading();//this method will have code to find the super heading这样的事情
有人知道如何从当前元素中检索超级标题元素吗?
发布于 2020-04-20 18:50:00
您可以使用xpath axes https://www.w3schools.com/xml/xpath_axes.asp。
尝试此//h3[text()= "title 3.2"]/parent::*
https://stackoverflow.com/questions/61317214
复制相似问题