不说明,注释都有
#coding=utf-8
import time
from appium import webdriver
#=============小米ROOT手机(微信)=============
class xiaomi:
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = '69MFPB66GA9L8L7D'
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI'
desired_caps['noReset'] = True
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(5)
#微信内访问debugx5.qq.com打开tbs内核调试
print('===========打开聊天框===========')
driver.find_element_by_xpath("//*[contains(@text, 'MrWang')]").click()
time.sleep(3)
print('===========发送微信消息===========')
driver.find_element_by_xpath("//*[contains(@class, 'android.widget.EditText')]").send_keys("https://xxx.com/index?channelId=1&partner_id=&pddCode=&v=1560250669845")
time.sleep(3)
driver.find_element_by_xpath("//*[contains(@text, '发送')]").click()
time.sleep(3)
print('===========获取页面内消息总数,并点击最后一条===========')
arr = driver.find_elements_by_xpath("//*[contains(@resource-id, 'com.tencent.mm:id/oe')]")
arr[arr.__len__() - 1].click()
time.sleep(15)
print('===========进入公众号页面===========')
driver.find_element_by_xpath("//*[contains(@text, '模块名字')]").click()
time.sleep(3)
driver.find_element_by_xpath("//*[contains(@resource-id, 'com.tencent.mm:id/fi7')]").click()
time.sleep(3)
driver.find_element_by_xpath("//*[contains(@resource-id, 'com.tencent.mm:id/kw')]").click()
time.sleep(3)
print('===========返回,向上滑动查看===========')
width = driver.get_window_size()['width']
height = driver.get_window_size()['height']
#向上滑动屏幕10次,找到指定元素时停止
i = 0
while i < 10:
try:
driver.find_element_by_xpath("//*[contains(@text, '被寻找的文字')]").click() # 尝试点击元素
break
except Exception as e:
time.sleep(1)
driver.swipe(width / 2, height * 0.8, width / 2, height * 0.2) # 滑动屏幕
i = i + 1
time.sleep(3)
print('===========脚本执行完成,退出微信===========')
driver.quit()