實現的效果在網盤
鏈接: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的
這就實現了~