分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

3-4 1449 web view

发布时间:2023-09-06 02:18责任编辑:沈小雨关键词:暂无标签


native app|纯原声app,Android用Java些,iOS用object c写
----------|---------------------------------------
hybrid app|套用原声应用的外壳,既有原生的UI页面,又通过内置web view组件(相当于内置浏览器),可以访问本地和远程的html文件,Native Hardware Access可以访问本地文件和通过js脚本或html调用本地的函数方法。
web app|只靠浏览器访问使用
微信小程序|微信内层嵌入的组件

模拟器默认支持
真机需要打开app内开关

//必须从您的应用启用web view调试。要启用web view调试,请在web view类上调用静态方法setWebContentsDebuggingEnabled。if (Build.VERSION.SDK_INT >= Build.VERSION_CODES>KITKAT){ ???WebView.setWebContentDebuggingEnabled(true)}
#代码有错误# 切换到web viewwebview = driver.contexts.lastdriver.switch_to.context(webview)#执行操作driver.find_element(:css,".green_button").click#切回原生页面driver.switch_to.context(driver.contexts.first)driver.quit()

 ??????@Test ???public void testWebview() throws InterruptedException { ???????WebDriverWait wait = new WebDriverWait(driver,10); ???????WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text=\"交易\"]"))); ???????System.out.println("等待结束"); ???????driver.findElementByXPath("//*[@text=\"交易\"]").click(); ???????Thread.sleep(10000); ???????Set<String> contextNames = driver.getContextHandles(); ???????System.out.println(contextNames); ???????System.out.println(contextNames); ???????System.out.println(contextNames); ???????System.out.println(contextNames); ???????System.out.println(contextNames); ???????Thread.sleep(3000); ???}

模拟器

使用真机,不会打印web view

使用API demo

 @Test ???public void testWebview() throws InterruptedException{ ???????WebDriverWait wait = new WebDriverWait(driver,10); ???????WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.TextView[@text=\"Views\"]"))); ???????driver.findElementByXPath("//android.widget.TextView[@text=\"Views\"]").click(); ???????WebElement list = driver.findElement(By.id("android:id/text1")); ???????MobileElement webview = list.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("+"new UiSelector().text(\"WebView\"));")); ???????//webview.click(); ???????driver.findElementByXPath("//android.widget.TextView[@text=\"WebView\"]").click(); ???????Thread.sleep(5000); ???????System.out.println(driver.getContextHandles()); ???????System.out.println(driver.getContextHandles()); ???????System.out.println(driver.getContextHandles()); ???????System.out.println(driver.getContextHandles()); ???????Thread.sleep(5000); ???}

使用真机依然只输出

关于web view测试的内容等待补充

FAQ

1.红米note5使用全面屏,控件By.xpath("//*[@text="交易"]")可以找到,但是控件属性显示不可点击。
解决方法:取消全面屏,使用经典导航键。控件可以正常访问。

2.使用真机,driver.getContextHandles();没有打印web view,使用UC也没有打印

3-4 1449 web view

原文地址:https://www.cnblogs.com/csj2018/p/9783524.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved