2015-03-19 50 views
2

我想匹配加载Salesforce登录页面(但也可以应用于具有文本字段的任何其他页面)的WebView内的用户名文本字段。匹配Android中Espresso的WebView中的视图

enter image description here

我曾尝试用:

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

但是,这并不工作。有什么更好的想法

+0

有没有人尝试使用Espresso 2.2 Web API来实现这一目标? – Raghu 2015-06-22 07:07:23

回答

3

这可以用咖啡的Web 2.2 API

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

如果我不知道定位符ID并且仅提示(TextView的)提示,例如“用户名”,该怎么办? – Raghu 2015-07-29 06:23:54

0

您可以填写表单,只需在WebView中运行js代码即可。 例如:

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

请使用Locator.Xpath,如果你不知道ID来实现。 要首先查找xpath,您需要检查可以写入xpath的html代码。 要获得html源代码,您可以使用chrome检查器。 将设备连接到PC,然后打开铬检查器。您可以右键单击该html代码并单击copy xpath以获取xpath。