David
David

Reputation: 910

Match a View in WebView from Espresso in Android

I want to match the user name text field inside a WebView which loads the Salesforce login page (but can also be applied to any other page with text fields).

enter image description here

I have tried with:

onView(withHint("User Name")).perform(typeText("[email protected]"));

But that doesn't work. Any better idea?

Upvotes: 3

Views: 4750

Answers (3)

anuja jain
anuja jain

Reputation: 1387

Please use Locator.Xpath if you don't know ID. To find xpath first you need to check the html code based on which you can write xpath. To get html source code you can use chrome inspector. connect the device to the PC and then open chrome inspector.You can right click on the html code and click on copy xpath to get the xpath.

Upvotes: 1

Nikitha
Nikitha

Reputation: 54

This can be accomplished using Espresso Web 2.2 API

onWebView().withElement(findElement(Locator.ID,"username")).perform(webKeys("[email protected]"));

Upvotes: 3

gildor
gildor

Reputation: 1894

You can fill form just run js code in WebView. For example:

webView.loadUrl("
   javascript:document.getElementById('username-field').value = '[email protected]’;
");

Upvotes: 0

Related Questions