---
title: "webdriver中Xpath当前节点寻找父节点下的字节点  "
author: "lvjun106"
date: "2016-04-03T12:20:20Z"
tags: []
categories: ["开源软件"]
slug: "webdriver-xpath"
draft: false
lastmod: "2016-04-03T12:20:20Z"
id: 2288274
url: "https://lvjun106.iteye.com/blog/2288274"
---

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

 

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

webdriver中Xpath当前节点寻找父节点下的字节点!