[英]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.