查看APP的webview的版本和Chromedriver的版本是否对应
确认webview的版本
找到APP中一个H5页,通过访问chrome://inspect/#devices这个网址来查看APPwebview的版本

然后根据版本号来寻找对应的Chromedriver的版本号,目前Android WebView支持主要还是靠ChromeDriver来实现
下载地址http://chromedriver.storage.googleapis.com/index.html

如我的版本是92.0.4515.105 则我需要的Chromedriver的版本是92.0.4515.105,如果没有找到完全匹配的版本没有则找最接近的一个版本,如我选择下载的是92.0.4515.107,下载成功后放到指定地址
通常native使用 APPIUM Inspector 进行元素定位,webview就不能使用APPIUM Inspector进行定位了,定位到的元素识别不了,webview 使用chrome://inspect/#devices里的Inspect 来进行定位,但是Chrome调试会报调试 HTTP/1.1 404 Not Found,国内网络限制所致,建议使用edge浏览器不需要翻墙
下载edge,输入edge://inspect/#devices

进行元素定位
调试你的代码
# Chrome 驱动地址
desired_capabilities[
'chromedriverExecutableDir'] = '/Users/cardloan/.nvm/versions/node/v16.20.0/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/'
desired_capabilities['chromedriverChromeMappingFile'] = '/Users/cardloan/Downloads/mapping.json'
# 禁用W3C检查,解决Cannot call non W3C standard command while in W3C mode报错
desired_capabilities['chromeOptions'] = {'w3c': False, 'androidProcess':'com.xiaoying.cardloan'} # 禁用W3C检查,测试H5时需要加上chromedriverExecutable参数,地址为上面下载好的Chromedriver地址

'chromeOptions': {"androidProcess":"com.xxx.cardloan", "androidUseRunningApp": True}中
androidProcess的获取方法
第一步在手机上提前打开webview页面,命令行中输入:adb shell dumpsys activity top|grep ACTIVITY
第二步拿到pid值输入:adb shell ps (pid值)
其中原生页面切换到H5时候需要使用
webview = driver.contexts[-1]
# 切换到web/hybrid 模式
driver.switch_to.context(webview)如果还报错确认APP中将webview的debug模式是否打开

mac 无法打开“chromedriver”,因为无法验证开发者
进入到chromedriver所在目录,执行xattr -d com.apple.quarantine chromedriver





Comments | NOTHING