appium-操作微信公众号和小程序

1:查看当前微信正在运行的微信公众号进程

C:\Users\edz>adb shell dumpsys activity top | findstr ACTIVITY
  ACTIVITY com.netease.cloudmusic/.activity.LockScreenActivity cb44411 pid=3869
  ACTIVITY com.tencent.mobileqq/.activity.SplashActivity 21ccf14 pid=6919
  ACTIVITY com.tencent.mm/.plugin.webview.ui.tools.WebViewUI 9e57c31 pid=18417
  ACTIVITY net.oneplus.launcher/net.oneplus.quickstep.RecentsActivity 9818f4e pid=3098
  ACTIVITY net.oneplus.h2launcher/.Launcher 71ce3d9 pid=3116
  ACTIVITY com.oneplus.gallery/.OPGalleryActivity 4b4055 pid=12000

2:查看当前进程的名称

C:\Users\edz>adb shell ps 18417
USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME
u0_a96       18417   884 2323872 217064 SyS_epoll_wait      0 S com.tencent.mm:tools

 

3:操作微信公众号或者小程序的desired_caps有:

desired_caps={
    'platformName':'Android',
    'uiautomationName':'uiautomator2',
    'platformVersion':'9',
    'deviceName':'e8dfc3c6',
    'appPackage':'com.tencent.mm',
    'appActivity':'.ui.LauncherUI',
    'automationName':'com.taobao.tao.welcome.Welcome',
    'unicodeKeyboard':True,
    'resetKeyboard':True,
    'noReset':True,
    'chromedriverExecutable':'D:\Program Files\chromedriver\\2.37\\chromedriver.exe',#指定微信小程序运行的chrome路径
    'chromeOptions':{'androidProcess':'com.tencent.mm:tools'},#指定微信小程序运行的进程
    'browserName':"",
    "recreateChromeDriverSessions":True
}

4:在进入H5页面后,需要切换上下文

print(driver.contexts)#打印所有的上下文
print(driver.current_context)#获取当前上下文
driver.switch_to.context("WEBVIEW_com.tencent.mm:tools")#跳转到我们需要的上下文
print(driver.current_context)
运行结果:
['NATIVE_APP', 'WEBVIEW_com.tencent.mm:tools']
NATIVE_APP
WEBVIEW_com.tencent.mm:tools

 

5:有的微信小程序在切换上下文后还是不能操作,可能就要跳转handler,因为不确定当前处于哪个窗口,所以可以这样做

handles=driver.window_handles
for handle in handles:
    driver.switch_to.window(handle)
    if driver.page_source.find("患者姓名")!=-1:
        break

 

转载于:https://www.cnblogs.com/Be-your-own-hero/p/11345558.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值