实现的效果在网盘
链接:https://pan.baidu.com/s/1tgLUJoXewOu0qQLp6ylu8A
提取码:sfnf

用到的工具:

  • 夜神模拟器
  • appium
  • pycharm
  • cmd
  • uiautomatorviewer
    需要注意的是:
    在这里插入图片描述
    这是主页面在这里插入图片描述
    这个的前提是appium,模拟器都必须打开

命令

  • adb start-server
  • adb devices在这里插入图片描述
    夜神模拟器
    在这里插入图片描述

用这个工具精确定位,以下也是在这里插入图片描述

一切准备就绪就可以编写自己想实现的功能
代码演示:

import time
from appium import webdriver

# server 启动参数
desired_caps = {
    # 设备信息
    'platformName': 'Android',
    'deviceName': '127.0.0.1:62001',
    # app的信息
    'appPackage': 'com.tencent.mobileqq',
    'appActivity':'.activity.SplashActivity',
    # 不清空数据
    "noReset": True,
    # 隐藏键盘
    "unicodeKeyboard":True,
    "resetKeyboard":True,
}
# 声明driver对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
time.sleep(1)

def denglu():
    time.sleep(1)
    driver.find_element_by_id("com.tencent.mobileqq:id/btn_login").click()
    print("点击登录了")

    time.sleep(1)
    driver.find_element_by_class_name("android.widget.EditText").clear()
    driver.find_element_by_class_name("android.widget.EditText").send_keys("2624393959")
    print("输入账号")

    time.sleep(1)
    driver.find_element_by_id("com.tencent.mobileqq:id/password").clear()
    driver.find_element_by_id("com.tencent.mobileqq:id/password").send_keys("zhenhan26243959")
    print("输入密码")

    time.sleep(1)
    driver.find_element_by_id("com.tencent.mobileqq:id/login").click()
    print("正式登录")

def xiaoxi():
    # 定位并点击消息输入框
    time.sleep(1)
    driver.find_element_by_id("com.tencent.mobileqq:id/relativeItem").click()
    print("点消息")

    # 定位并点击书写输入框
    time.sleep(1)
    driver.find_element_by_class_name("android.widget.EditText").click()
    print("点输入框")

    # 书写输入框
    time.sleep(1)
    driver.find_element_by_class_name("android.widget.EditText").send_keys("😄哈哈,今天天气真不错,(●'◡'●)")
    driver.find_element_by_class_name("android.widget.Button").click()
    print("写入内容")
    time.sleep(5)
    # 关闭程序
    driver.quit()

if __name__ == '__main__':
    a = denglu()
    b = xiaoxi()

app的信息
‘appPackage’: ‘com.tencent.mobileqq’,
‘appActivity’:’.activity.SplashActivity’,
在cmd里输入命令:
1. Mac/Linux: 'adb shell dumpsys window windows | grep mFocusedApp’
2. 在 Windows 终端运行 'adb shell dumpsys window windows’ 然后去看mFocusedApp这一行的内容。

我是Windows的在这里插入图片描述
这就实现了~

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐