Xpath当前节点寻找父节点下的子节点

HTML的结构如下:

<section class="AutoTest">
    <a title="xpath"  href="#"></a>
    <div style="#">
        webdriver  ui  auto Test !
    </div>
</section>

我们首先需要获取title=”xpath”的节点,

Xpath写法为

driver.findElements(By.xpath("//a[@title='xpath']")) 

然后我们在获取他的父节点

driver.findElements(By.xpath("//a[@title='xpath']/parent::section")) 

我们在查找子节点div下的文本内容,

driver.findElements(By.xpath("//a[@title='xpath']/parent::section/div/text()"))

通过以上我们可以查找的相关的节点

猜你喜欢

转载自blog.csdn.net/jasonlee_lijiaqi/article/details/80309496
今日推荐