zoukankan      html  css  js  c++  java
  • python自动化:微信公众号

    1. 确保手机已与电脑连接

    2. 开启微信debug模式

      在微信聊天界面输入:debugx5.qq.com,勾选"打开TBS内核Inspector调试功能”

    3. 查看微信里面webview版本

      在电脑chrome浏览器输入:chrome://inspect/#devices,再打开微信的公众号页面,刷新浏览器页面,就会出现webview版本号,点击“inspect”即可定位元素

    4. 下载对应版本的chromedriver

      下载的对应版本的chromedriver替换该路径: ode_modulesappium ode_modulesappium-chromedriverchromedriverwin下的chromedriver

    5. 获取公众号的进程名字

      adb shell

      dumpsys activity top | grep ACTIVITY

      ps 进程的pid

    6. 实现代码如下:

    from appium import webdriver
    import time
    
    di = {}
    di['platformName'] = 'Android'
    di['platformVersion'] = '6.0'
    di['deviceName'] = 'Appium'
    di['unicodeKeyboard'] = True
    di['resetKeyboard'] = True
    di['appPackage'] = 'com.tencent.mm'
    di['appActivity'] = '.ui.LauncherUI'
    di['udid'] = '127.0.0.1:62001'
    # di['automationName']='uiautomator2'
    #不同点
    di[ 'chromeOptions']="{'androidProcess': 'com.tencent.mm:tools'}"
    driver = webdriver.Remote('http://localhost:4723/wd/hub',di)
    time.sleep(5)
    driver.implicitly_wait(20)
    # 点微信首页搜索按钮
    driver.find_element_by_accessibility_id("搜索").click()
    # 输入内容搜索
    time.sleep(3)
    driver.find_element_by_id('com.tencent.mm:id/hx').send_keys("yx")
    # 点开公众号
    time.sleep(3)
    driver.find_element_by_id('com.tencent.mm:id/l7').click()
    # 点公众号菜单-精品分类
    time.sleep(3)
    driver.find_elements_by_id('com.tencent.mm:id/aaq')[0].click()
    #不同点,切换到webview
    time.sleep(2)
    print(driver.contexts)
    driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
    time.sleep(3)
    #切换句柄
    handles=driver.window_handles
    driver.switch_to_window(handles[1])
    driver.find_element_by_xpath(".//*[@id='namespace_1']/div[1]/div/div[2]").click()
  • 相关阅读:
    今天没有写的,唱首歌吧。。
    UILocalNotification实现本地的闹钟提醒的方法。
    又是动画效果~
    c位运算符
    javascript如何调用objectivec的方法
    在tableview索引中显示搜索符号的方法
    检查数据库|| 复制数据库文件
    往sqlite中写入图片二进制数据及读取源码 for iphone
    [Cocoa]深入浅出 Cocoa 之消息(罗朝辉)
    关于malloc问题的改错笔试常考
  • 原文地址:https://www.cnblogs.com/badbadboyyx/p/12202910.html
Copyright © 2011-2022 走看看