https://blog.csdn.net/weixin_45912307/article/details/122392478
1. 獲取作業系統版本
2. 獲取裝置名稱
aapt.exe
目錄下aapt dump badging apk
安裝路徑(如C:\Users\使用者名稱稱\Downloads\Android_8.8.55.6900_537105254_32.apk
)# 1. 從appium庫裡匯入driver物件
from appium import webdriver
# 2. server啟動引數
desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1'
desired_caps['deviceName'] = 'emulator-5554'
desired_caps['appPackage'] = 'com.tencent.mobileqq'
desired_caps['appActivity'] = 'com.tencent.mobileqq.activity.SplashActivity'
# 3. 宣告driver物件
driver = webdriver.Remote('http://127.0.0.1:5554/wd/hub', desired_caps)
1. 安裝工具
pip install -U uiautomator2 | 安裝第三方庫
python -m uiautomator2 init | 初始化uiautomator2
pip install -U weditor | 安裝定位工具
weditor --help | 檢查是否安裝成功
weditor | 啟動定位工具(網頁版)
2. 工具使用
1. 點選appium搜尋按鈕
2. 填寫連線裝置引數
注:點選「start session」前必須開啟需要定位元素所在頁面
{
"platformName": "Android",
"platformVersion": "5.1.1",
"deviceName": "emulator-5554",
"appPackage": "com.tencent.mobileqq",
"appActivity": "com.tencent.mobileqq.activity.LoginActivity",
"noRest": false
}
3. 工具使用及解讀
id | driver.find_element_by_id(id_value)
ANDROID_UIAUTOMATO | Rnew UiSelector().方法名稱(值).方法名稱(值).方法名稱(值)
xpath | driver.find_element_by_xpath(xpath_value)
description content-desc | driver.find_element_by_accessibility_id('view-text')
className | driver.find_element_by_class_name(class_value)
座標 | os.system('adb shell tap x y')
模糊定位 | contains(@key,value)
# 1. 從appium庫裡匯入driver物件
import time
from appium import webdriver
# 2. server啟動引數
def denglu():
desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1'
desired_caps['deviceName'] = 'emulator-5554'
desired_caps['appPackage'] = 'com.tencent.mobileqq'
desired_caps['appActivity'] = 'com.tencent.mobileqq.activity.SplashActivity'
desired_caps['noRest'] = True
# 3. 宣告driver物件
driver = webdriver.Remote('http://127.0.0.1:5554/wd/hub', desired_caps)
driver.implicitly_wait(10)
# 4. 點選登入
driver.find_element_by_id("com.tencent.mobileqq:id/btn_login").click()
# 5. 輸入使用者名稱
user_name = driver.find_element_by_xpath('//*[@content-desc="請輸入QQ號碼或手機或郵箱"]')
# 清除輸入框
user_name.clear()
user_name.send_keys('492224xxxx')
# 6. 輸入密碼
user_pwd = driver.find_element_by_id('com.tencent.mobileqq:id/password')
# user_pwd = driver.find_element_by_xpath('//*[@resource-id="com.tencent.mobileqq:id/password"]')
# 清除輸入框
user_pwd.clear()
user_pwd.send_keys('xxxxx')
# 7.勾選同意協定
driver.find_element_by_xpath('//*[@resource-id="com.tencent.mobileqq:id/pqz"]').click()
# 8.點選登入
driver.find_element_by_xpath('//*[@resource-id="com.tencent.mobileqq:id/login"]').click()
# 退出或關閉驅動
time.sleep(15)
driver.quit()