# DomMatchers

Summary:[Methods](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#)  

# DomMatchers

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
DomMatchers
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|-------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.espresso.web.matcher.DomMatchers |

<br />

*** ** * ** ***

A collection of hamcrest matchers for objects in the org.w3c.dom package (such as[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)and[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)).

## Summary

|                                                                                                                                                                                                                                                                                                                                                      ### Public methods                                                                                                                                                                                                                                                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | ` `[containingTextInBody](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#containingTextInBody(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` text) ` Returns a matcher that matches Documents that have a body containing the given test.                                                                                                                                                                                                                                                                                   |
| ` static Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | ` `[elementById](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#elementById(java.lang.String, org.hamcrest.Matcher<org.w3c.dom.Element>))`(`[String](https://developer.android.com/reference/java/lang/String.html)` id, Matcher<`[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)`> elementMatcher) ` Matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s that have an[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)with the given id that matches the given element matcher.   |
| ` static Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | ` `[elementByXPath](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#elementByXPath(java.lang.String, org.hamcrest.Matcher<org.w3c.dom.Element>))`(`[String](https://developer.android.com/reference/java/lang/String.html)` xpath, Matcher<`[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)`> elementMatcher) ` Matches a XPath and validates it against the first[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)that it finds in the[NodeList](https://developer.android.com/reference/org/w3c/dom/NodeList.html). |
| ` static Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | ` `[hasElementWithId](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#hasElementWithId(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` id) ` Returns a matcher that matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s that have at least one element with the given id.                                                                                                                                                                                                                   |
| ` static Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | ` `[hasElementWithXpath](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#hasElementWithXpath(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` xpath) ` Returns a matcher that matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s that have at least one element with the given xpath.                                                                                                                                                                                                       |
| ` static Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | ` `[withBody](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#withBody(org.hamcrest.Matcher<org.w3c.dom.Element>))`(Matcher<`[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)`> bodyMatcher) ` Returns a matcher that matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s with body that matches the given matcher.                                                                                                                                                                                            |
| ` static Matcher<`[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)`>`   | ` `[withTextContent](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#withTextContent(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` textContent) ` Returns a matcher that matches[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)s with the given textContent.                                                                                                                                                                                                                                    |
| ` static Matcher<`[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)`>`   | ` `[withTextContent](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#withTextContent(org.hamcrest.Matcher<java.lang.String>))`(Matcher<`[String](https://developer.android.com/reference/java/lang/String.html)`> textContentMatcher) ` Returns a matcher that matches[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)s that have textContent matching the given matcher.                                                                                                                                                                        |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## Public methods

### containingTextInBody

```
Matcher<Document> containingTextInBody (String text)
```

Returns a matcher that matches Documents that have a body containing the given test.

<br />

|       Parameters        ||
|--------|-----------------|
| `text` | `String` <br /> |

|                                              Returns                                               ||
|--------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | <br /> |

### elementById

```
Matcher<Document> elementById (String id, 
                Matcher<Element> elementMatcher)
```

Matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s that have an[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)with the given id that matches the given element matcher.

<br />

|             Parameters             ||
|------------------|------------------|
| `id`             | `String` <br />  |
| `elementMatcher` | `Matcher` <br /> |

|                                              Returns                                               ||
|--------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | <br /> |

### elementByXPath

```
Matcher<Document> elementByXPath (String xpath, 
                Matcher<Element> elementMatcher)
```

Matches a XPath and validates it against the first[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)that it finds in the[NodeList](https://developer.android.com/reference/org/w3c/dom/NodeList.html).

<br />

|             Parameters             ||
|------------------|------------------|
| `xpath`          | `String` <br />  |
| `elementMatcher` | `Matcher` <br /> |

|                                              Returns                                               ||
|--------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | <br /> |

### hasElementWithId

```
Matcher<Document> hasElementWithId (String id)
```

Returns a matcher that matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s that have at least one element with the given id.

<br />

|      Parameters       ||
|------|-----------------|
| `id` | `String` <br /> |

|                                              Returns                                               ||
|--------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | <br /> |

### hasElementWithXpath

```
Matcher<Document> hasElementWithXpath (String xpath)
```

Returns a matcher that matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s that have at least one element with the given xpath.

<br />

|        Parameters        ||
|---------|-----------------|
| `xpath` | `String` <br /> |

|                                              Returns                                               ||
|--------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | <br /> |

### withBody

```
Matcher<Document> withBody (Matcher<Element> bodyMatcher)
```

Returns a matcher that matches[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)s with body that matches the given matcher.

<br />

|           Parameters            ||
|---------------|------------------|
| `bodyMatcher` | `Matcher` <br /> |

|                                              Returns                                               ||
|--------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Document](https://developer.android.com/reference/org/w3c/dom/Document.html)`>` | <br /> |

### withTextContent

```
Matcher<Element> withTextContent (String textContent)
```

Returns a matcher that matches[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)s with the given textContent. Equivalent of withTextContent(is(textContent)).

<br />

|           Parameters           ||
|---------------|-----------------|
| `textContent` | `String` <br /> |

|                                             Returns                                              ||
|------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)`>` | <br /> |

### withTextContent

```
Matcher<Element> withTextContent (Matcher<String> textContentMatcher)
```

Returns a matcher that matches[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)s that have textContent matching the given matcher.

<br />

|               Parameters               ||
|----------------------|------------------|
| `textContentMatcher` | `Matcher` <br /> |

|                                             Returns                                              ||
|------------------------------------------------------------------------------------------|--------|
| `Matcher<`[Element](https://developer.android.com/reference/org/w3c/dom/Element.html)`>` | <br /> |

-

  ## Classes

  - [DomMatchers](https://developer.android.com/reference/android/support/test/espresso/web/matcher/DomMatchers)
-

  ## Exceptions

  - [AmbiguousElementMatcherException](https://developer.android.com/reference/android/support/test/espresso/web/matcher/AmbiguousElementMatcherException)