java - 如何识别当前标题的 super (父)标题级别

标签 java selenium-webdriver testng

假设我在页面上有一些这样的标题

<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/

相关文章:

javascript - 无法使用 JavaScript 关闭 chrome 浏览器中的选项卡

c# - 使用 Selenium 使用 WindowHandles 跟踪和遍历选项卡和窗口的最佳方法

java - 单元测试时静态元模型属性为空

java - Maven 和单元测试 - 结合 Maven Surefire 插件和 testNG Eclipse 插件

java - 在 Apache Karaf 的日志文件中打印 System.out.println

java - XStream 使用 NamedMapConverter 序列化自定义 Map

python - 在python中使用selenium查找通过类名找到的元素的id

java - testng - 在 testng.xml 中将列表作为参数传递

java - 拦截 URL 和过滤器

java - 了解自定义 JRE(Java 中的模块)