# Web.WebInteraction

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

# Web.WebInteraction

| 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
static


class
Web.WebInteraction
`  
`

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.sugar.Web.WebInteraction\<R\> |

<br />

*** ** * ** ***

Analogous to a ViewInteraction or a DataInteraction, a WebInteraction exposes a fluent API to the underlying WebView.

## Summary

|                                                                                                                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                                                                                                                     ||
|----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` <E> `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<E>` | ` `[check](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#check(android.support.test.espresso.web.assertion.WebAssertion<E>))`(`[WebAssertion](https://developer.android.com/reference/android/support/test/espresso/web/assertion/WebAssertion)`<E> assertion) ` Evaluates the given WebAssertion.                                                                                                                                                                                                                                 |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[forceJavascriptEnabled](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#forceJavascriptEnabled())`() ` Performs a force enable of Javascript on a WebView.                                                                                                                                                                                                                                                                                                                                                                       |
| ` R`                                                                                                                             | ` `[get](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#get())`() ` Returns the result of a prior call to perform or check.                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[inWindow](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#inWindow(android.support.test.espresso.web.model.WindowReference))`(`[WindowReference](https://developer.android.com/reference/android/support/test/espresso/web/model/WindowReference)` window) ` Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.                                                                                                                                                                            |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[inWindow](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#inWindow(android.support.test.espresso.web.model.Atom<android.support.test.espresso.web.model.WindowReference>))`(`[Atom](https://developer.android.com/reference/android/support/test/espresso/web/model/Atom)`<`[WindowReference](https://developer.android.com/reference/android/support/test/espresso/web/model/WindowReference)`> windowPicker) ` Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.                        |
| ` <E> `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<E>` | ` `[perform](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#perform(android.support.test.espresso.web.model.Atom<E>))`(`[Atom](https://developer.android.com/reference/android/support/test/espresso/web/model/Atom)`<E> atom) ` Executes the provided atom within the current context (the combination of Window and Element References).                                                                                                                                                                                          |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[reset](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#reset())`() ` Removes the Element and Window references from this interaction.                                                                                                                                                                                                                                                                                                                                                                                            |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[withContextualElement](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#withContextualElement(android.support.test.espresso.web.model.Atom<android.support.test.espresso.web.model.ElementReference>))`(`[Atom](https://developer.android.com/reference/android/support/test/espresso/web/model/Atom)`<`[ElementReference](https://developer.android.com/reference/android/support/test/espresso/web/model/ElementReference)`> elementPicker) ` Allows for contextually evaluating this WebInteraction with the selected element. |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[withElement](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#withElement(android.support.test.espresso.web.model.ElementReference))`(`[ElementReference](https://developer.android.com/reference/android/support/test/espresso/web/model/ElementReference)` element) ` Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.                                                                                                                                                          |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[withElement](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#withElement(android.support.test.espresso.web.model.Atom<android.support.test.espresso.web.model.ElementReference>))`(`[Atom](https://developer.android.com/reference/android/support/test/espresso/web/model/Atom)`<`[ElementReference](https://developer.android.com/reference/android/support/test/espresso/web/model/ElementReference)`> elementPicker) ` Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.      |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[withNoTimeout](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#withNoTimeout())`() ` Disables all Timeouts on this WebInteraction.                                                                                                                                                                                                                                                                                                                                                                                               |
| ` `[WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>`     | ` `[withTimeout](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#withTimeout(long, java.util.concurrent.TimeUnit))`(long amount, `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit.html)` unit) ` Sets a specific timeout for this WebInteraction.                                                                                                                                                                                                                                                   |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#)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

### check

```
WebInteraction<E> check (WebAssertion<E> assertion)
```

Evaluates the given WebAssertion.

The WebAssertion's atom is evaluated, after it's evaluation completes, the WebAssertion is run on the main thread to perform further checks. The WebAssertion is given the Atom's result and the WebView it had run against.

After this method completes, the result of the atom's evaluation is avaliable via get.

<br />

|             Parameters             ||
|-------------|-----------------------|
| `assertion` | `WebAssertion` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<E>` | <br /> |

### forceJavascriptEnabled

```
WebInteraction<R> forceJavascriptEnabled ()
```

Performs a force enable of Javascript on a WebView.

All WebView interactions are done via Javascript - therefore the WebView we are working on must support Javascript evaluation.

Enabling Javascript may cause the WebView under test to be reloaded. This is necessary to ensure the test infrastructure javascript bridges are loaded by the WebView.

<br />

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

### get

```
R get ()
```

Returns the result of a prior call to perform or check.

<br />

|   Returns   ||
|-----|--------|
| `R` | <br /> |

### inWindow

```
WebInteraction<R> inWindow (WindowReference window)
```

Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.

By default Javascript may be evaluated in the main window. However in an application which uses frames, you may want to evaluate in another frame.

<br />

|             Parameters             ||
|----------|--------------------------|
| `window` | `WindowReference` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

### inWindow

```
WebInteraction<R> inWindow (Atom<WindowReference> windowPicker)
```

Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.

This method accepts an Atom which will be evaluated in the main window to choose a particular DOM window for further interactions. This method will block until the the provided Atom returns with a result.

<br />

|          Parameters           ||
|----------------|---------------|
| `windowPicker` | `Atom` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

### perform

```
WebInteraction<E> perform (Atom<E> atom)
```

Executes the provided atom within the current context (the combination of Window and Element References).

This method blocks until the Atom returns. The result of the Atom's evaluation is used to create a new instance of WebInteraction which can be used to access the result of the Atom's evaluation.

<br />

|      Parameters       ||
|--------|---------------|
| `atom` | `Atom` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<E>` | <br /> |

### reset

```
WebInteraction<R> reset ()
```

Removes the Element and Window references from this interaction.

This is usually necessary when a prior action (for example a click) introduces a navigation that invalidates the ElementReference and WindowReference pointers.

<br />

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

### withContextualElement

```
WebInteraction<R> withContextualElement (Atom<ElementReference> elementPicker)
```

Allows for contextually evaluating this WebInteraction with the selected element.

Specifically the elementPicker atom will be evaluated with the CURRENTLY selected element to discover the new element to work against.

This allows callers to interact with a document that looks like this:  

```
 <div id="teacher">
   <div id="person_name">
     <p>Socrates</p>
   </div>
 </div>
 <div id="student">
   <div id="person_name">
     <p>Plato</p>
   </div>
 </div>
 
 
```
With code like this:  

    onWebView()
       .withElement(findElement(Locator.ID, "teacher"))
       .withContextualElement(findElement(Locator.ID, "person_name"))
       .check(webMatches(getText(), containsString("Socrates")));
     
<br />

<br />

|           Parameters           ||
|-----------------|---------------|
| `elementPicker` | `Atom` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

### withElement

```
WebInteraction<R> withElement (ElementReference element)
```

Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.

Calling this method resets any previously selected ElementReference.

<br />

<br />

|              Parameters              ||
|-----------|---------------------------|
| `element` | `ElementReference` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

**See also:**

- [getArguments(ElementReference)](https://developer.android.com/reference/android/support/test/espresso/web/model/Atom#getArguments(android.support.test.espresso.web.model.ElementReference))  

### withElement

```
WebInteraction<R> withElement (Atom<ElementReference> elementPicker)
```

Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.

<br />

This method accepts an Atomwhich it will evaluate on the current context's Window. This method blocks until the evaluation completes.

Calling this method resets any previously selected ElementReference.

If you want to evaluate the elementPicker in the context of the previously selected ElementReference

<br />

|           Parameters           ||
|-----------------|---------------|
| `elementPicker` | `Atom` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

**See also:**

- [getArguments(ElementReference)](https://developer.android.com/reference/android/support/test/espresso/web/model/Atom#getArguments(android.support.test.espresso.web.model.ElementReference))
- [withContextualElement(Atom)](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction#withContextualElement(android.support.test.espresso.web.model.Atom<android.support.test.espresso.web.model.ElementReference>))  

### withNoTimeout

```
WebInteraction<R> withNoTimeout ()
```

Disables all Timeouts on this WebInteraction.

Javascript evaluation is performed asynchronously on the WebKit/Chromium thread. By default we wait a short while for the result to be delivered back to the test.

<br />

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

### withTimeout

```
WebInteraction<R> withTimeout (long amount, 
                TimeUnit unit)
```

Sets a specific timeout for this WebInteraction.

<br />

|         Parameters          ||
|----------|-------------------|
| `amount` | `long` <br />     |
| `unit`   | `TimeUnit` <br /> |

|                                                              Returns                                                              ||
|---------------------------------------------------------------------------------------------------------------------------|--------|
| [WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)`<R>` | <br /> |

-

  ## Classes

  - [Web](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web)
  - [Web.WebInteraction](https://developer.android.com/reference/android/support/test/espresso/web/sugar/Web.WebInteraction)