我有一个场景,我需要获取下一个标签名称,该名称将显示在给定的元素定位器之后。
假设在下面的代码中,如果我有指向突出显示的div 标签的 xpath,并且我想获取它旁边显示的标签名称(此处的示例"h1"(。
<body>
<div>
<img>
**<div>**
<h1>
解决方案将取决于它是什么: 如果是兄弟姐妹:
//div['xpath of your div']//following::h1
如果是孩子:
//div['xpath of your div']//child::h1
driver.findElement(By.xpath("//div['xpath of your div']/following::*[1]"))
.getTagName();