[英]How to get the next tag displayed after the given xpath location
我有一个场景,我需要获取要在给定元素定位符之后显示的下一个标记名称。
假设在下面的代码中,如果我对突出显示的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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.