简体   繁体   English

如何在给定的xpath位置之后显示下一个标签

[英]How to get the next tag displayed after the given xpath location

I have a scenario, where I need to get the next tag name which is going to displayed after the given element locator. 我有一个场景,我需要获取要在给定元素定位符之后显示的下一个标记名称。

Suppose in the following code, if i have xpath to the highlighted div tag and i want to get the tag name displayed next to it(Example "h1" here). 假设在下面的代码中,如果我对突出显示的div标签具有xpath,并且想要在其旁边显示标签名称(此处为示例“ h1”)。

<body>
<div>
<img>
**<div>**
<h1>

Solution would depend on what it is: if it is a sibling: 解决方案将取决于它是什么:如果它是兄弟姐妹:

//div['xpath of your div']//following::h1

if it's a child: 如果是孩子:

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM