- Android系统控件
- 用来展示web页面
- 在系统中作为单独的系统应用存在(特殊)
- Step1:准备android 4.4+版本以上的手机/模拟器
- Step2:在app源码中将webview调试模式打开--请开发帮忙去打开webview.setWebContentsDebuggingEnabled(true);
- Step3:安装UC开发者工具 (这是它的官网:https://dev.ucweb.com/)--识别App内嵌的web页面元素的,识别webview版本,识别web页面元素
- Step4:下载webview对应匹配的chromedriver
- Step1:识别 - webview视图
- Step2:获取所有的contexts:driver.getContextHandles();
- Step3:切换 - 切换到webview视图:driver.context(webview视图);
- Step4:定位 - 定位webview中的元素,并执行操作:web网页元素定位和操作。
- Step5:切换 - 切换回默认的视图:driver.context(native视图)
- 在程序中context我们可以理解为当前对象在程序中所处的一个环境/状态
- native界面和webview界面分属于不同的context,前者基于Andriod原生控件,后者是Web网页
- native默认是”NATIVE_APP”,webview则默认是”WEBVIEW_被测进程名称”
- 两者的运行环境不同因此需要进行上下文(context)切换
//获取当前context
System.out.println("进入到apple社区之前的:"+driver.getContextHandles());
//点击主页上的apple社区
driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().text(\"apple社区\")")).click();
Thread.sleep(3000);
//NATIVE_APP 原生页面对应的context(模式名)
//WEBVIEW_com.apple.apple2 web页面对应的context
System.out.println("进入到apple社区之后的:"+driver.getContextHandles());
//App自动化代码执行默认是用的native模式,如果要定位web页面的元素信息,就必须要切换到web模式下
//重点:切换context
driver.context("WEBVIEW_com.apple.apple2");
//定位web元素信息
//driver.findElement(By.xpath("//a[text()='注册']")).click();
driver.findElement(By.xpath("//a[@href='http://shoppingarea.com/login' and @class='index-bottom__item']")).click();
// //a[@href='http://shoppingarea.com/login' and @class='index-bottom__item']
driver.findElement(By.id("name")).sendKeys("13230567889");
driver.findElement(By.id("Password")).sendKeys("23456");
driver.findElement(By.id("Login")).click();
原文地址:https://www.cnblogs.com/zhiyu07/p/14187185.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。