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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM