robotium之webview元素处理
今天写robotium脚本发现,用uiautomatorviewer定位百度贴吧的登录框是无法定位的,如图:

明显无法定位用户名、密码输入框,无法定位元素那就无法对控件无法操作
如何定位webview元素?
解决方案:
step:
1、手机连接上电脑,并打开App,打开需要定位的Webview的页面
2、电脑上打开Chrome,地址栏输入 chrome://inspect
3、点击devices标签,此时你会看到你设备上对应的App的包名
ps:必须翻墙链接外网,否则看不到效果

4、点击包名旁边的 inspect ,就会进入chrome的调试工具,在这个调试工具就可以获取
当前webview的所有元素了。

测试百度app登录源码:
package com.example.tieba.test; import org.junit.After;
import org.junit.Before;
import org.junit.Test; import android.os.PowerManager;
import android.test.ActivityInstrumentationTestCase2; import com.robotium.solo.By;
import com.robotium.solo.Solo; public class TestBaiduApp extends ActivityInstrumentationTestCase2 { // 定义变量
private Solo solo;
private static final String packageName = "com.baidu.tieba";
private static final String launchActivityName = "com.baidu.tieba.LogoActivity";
private PowerManager.WakeLock wakeScreenObject = null;
// 定义启动activity类
private static Class<?> loginActivity;
// 通过初始化静态块,加载启动activity
static {
try {
loginActivity = Class.forName(launchActivityName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public TestBaiduApp() {
super(packageName, loginActivity);
// TODO Auto-generated constructor stub
}
private void init() {
solo = new Solo(getInstrumentation(), getActivity());
solo.scrollToSide(solo.LEFT, 0.9f);
// 唤醒设备
if (wakeScreenObject == null) {
wakeScreenObject = Util.wakeScreen(this);
}
}
@Before
protected void setUp() throws Exception {
super.setUp();
init(); } @After
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
} @Test
public void test() {
assertTrue("如没进入登录页,可能有bug", solo.waitForText("随便看看", 1, 2000));
solo.clickOnText("登录",1);
//webview元素处理
// 输入用户名
solo.clearTextInWebElement(By.id("login-username"));
solo.enterTextInWebElement(By.id("login-username"), username);
// 输入密码
solo.clearTextInWebElement(By.id("login-password"));
solo.enterTextInWebElement(By.id("login-password"), password);
// 点击登录
solo.clickOnWebElement(By.id("login-submit"),1);
solo.sleep(10000);
} }
robotium之webview元素处理的更多相关文章
- Robotium源码解读-native控件/webview元素的获取和操作
目前比较有名的Uitest框架有Uiautomator/Robotium/Appium,由于一直对webview元素的获取和操作比较好奇,另外Robotium代码量也不是很大,因此打算学习一下. 一. ...
- H5混合应用之webview元素定位工具
一.工具选择 webview元素定位有三种方式: 使用driver.page_source方法,将获取到的页面内容写入到一个html文件中,然后使用浏览器打开html文件,使用F12调试用具进行元素定 ...
- webview元素定位
genymotion 模拟器:android 5.0.0 python 2.7 appium 1.4.16.1 1.app原生元素定位(常用) driver.find_element_by_id(“ ...
- Appium 自动化测试(9) -- 在Uiautomator中查看webview元素
在uiautomator中,直接查看不到webview中的元素,不知道大家遇到过没有?如下 解决方法如下: step0:将uiautomator关闭 step1:在appium 中,设置Android ...
- ios与js交互获取webview元素和赋值
使用webview的stringByEvaluatingJavaScriptFromString的方法交互,直接提供实例. 下载:http://download.csdn.net/detail/hey ...
- 解决 hybird 应用中重复获取 WebView,导致页面元素无法识别的问题
转载地址:http://blog.csdn.net/testman930/article/details/50799532 问题描述 在测APP的业务流,WebView和Native模式耦合在一起.例 ...
- Android——WebView
WebView用途 通过Intent调用系统浏览器: 引言: Uri uri = Uri.parse(url);//url为你要链接的地址 Intent intent = new Intent(Int ...
- Robotium原则的实施源代码分析
从前面的章节<Robotium源代码分析之Instrumentation进阶>中我们了解到了Robotium所基于的Instrumentation的一些进阶基础.比方它注入事件的原理等,但 ...
- Robotium源码分析之运行原理
从上一章<Robotium源码分析之Instrumentation进阶>中我们了解到了Robotium所基于的Instrumentation的一些进阶基础,比如它注入事件的原理等,但Rob ...
随机推荐
- A1077. Kuchiguse
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- MSSQL获取当前插入的ID号及在高并发的时候处理方式
SQL Server 2000中,insert数据的时候返回自动编号的id,有三种方法实现SCOPE_IDENTITY.IDENT_CURRENT 和 @@IDENTITY,它们都返回插入到 IDEN ...
- javascript高级程序设计第二章知识点提炼
这是我整理的javascript高级程序设计第二章的脑图,内容也是非常浅显与简单.希望您看了我的博客能够给我一些意见或者建议.
- poj3660(Cow Contest)解题报告
Solution: 传递闭包 //if a beats b and b beats c , then a beats c //to cow i, if all the result of conten ...
- Codeforce Div-3 E.Cyclic Components
You are given an undirected graph consisting of nn vertices and mm edges. Your task is to find the n ...
- 过时date.toLocaleString()的解决方法
System.out.println(new java.util.Date()); 输出:Thu Jan 27 14:43:28 CST 2011 System.out.println(new jav ...
- JavaSE学习总结(四)——Java面向对象十分钟入门
面向对象编程(Object Oriented Programming,OOP)是一种计算机模拟人类的自然思维方式的编程架构技术,解决了传统结构化开发方法中客观世界描述工具与软件结构的不一致性问题.Ja ...
- SQL记录-解锁和dbms_job操作
创建JOB create or replace procedure proc_auto_exec_job as begin declare job number; BEGIN dbms_job.sub ...
- CM记录-选择合适的硬件
hadoop的运行环境---hadoop/jvm/os/hw 原则1:主节点的可靠性要好于从节点:NameNode(Yarn-ResourceManager).DataNode(NodeManager ...
- CentOS下设置vim的tab键为4格
# vim /etc/vimrc 在最后一行添加 set softtabstop=4 或者set tabstop=4 或者在~/.vimrc中添加也可以 没有~/.vimrc文件可以创建一个 另: s ...