前言:
- 微信:已成功定位并解决自动化问题
- 钉钉:目前可以定位到,但是代码无法切换webview
appium+微信
-
把微信的开发者模式调出 debugx5.qq.com
随意发送消息,内容为“debugx5.qq.com”。点击debugx5.qq.com, 这就会跳转至微信的x5内核调试页面
信息—勾选"是否打开TBS内核Inspector调试功能
2.在谷歌输入“chrome://inspect/#devices” ,点击微信内部
会显示出相应链接,点击inspect即可出现定位页面
注意:
如果inspect之后,页面不能显示/显示404,则需要登录vpn,即可显示 -
代码部分
import time
import unittest
import warnings
import unittest2
from appium import webdriver
class BaseTestCaseWX3(unittest2.TestCase):
def setUp(self):
warnings.filterwarnings("ignore")
self.caps={
"platformName": "Android",
# mate8
"platformVersion": "8.0.0",
"deviceName": "5LM0216729001841",
"automationName": "Appium", # Appium版本:1.8.2
# 微信
"appPackage": "com.tencent.mm",
"appActivity": "com.tencent.mm.ui.LauncherUI",
"noReset": "true",
# 键盘
"unicodeKeyboard": True, # 使用unicode编码方式发送字符串
"resetKeyboard": True, # 把键盘隐藏起来
# webview的进程名,查到的是com.tencent.mm:tools
"chromeOptions": {
"androidProcess": "com.tencent.mm:tools"
}
}
self.driver=webdriver.Remote("http://localhost:4723/wd/hub", self.caps)
#self.driver.implicitly_wait(10)
time.sleep(10)
# 打印所有页面会打印出俩: ['NATIVE_APP','WEBVIEW_com.tencent.mm:tools']
print(self.driver.contexts)
time.sleep(3)
# 切换至webview页面
self.driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
time.sleep(5)
亲自使用,可以正常使用,作为记录也为他人提供方便。