简体   繁体   中英

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).

在此输入图像描述

I have tried with:

onView(withHint("User Name")).perform(typeText("test@sf.com"));

But that doesn't work. Any better idea?

这可以使用Espresso Web 2.2 API完成

onWebView().withElement(findElement(Locator.ID,"username")).perform(webKeys("test@sf.com"));

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

webView.loadUrl("
   javascript:document.getElementById('username-field').value = 'test@sf.com’;
");

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM