简体   繁体   中英

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

<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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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