启动Appium Server GUI
1,启动之后点击编辑配置
2,添加ANDROID_HOME
保存重启生效
3,启动服务器
连接手机
1,数据线连接
手机打开usb调试,启动Appium Server GUI
进入终端,输入:adb devices
adb devices
List of devices attached
52ec8352 device
2,WIFI连接
确保手机与PC在同一网络下 1,先使用数据线连接 2,连接成功后,终端输入
adb tcpip port # 指定端口号
adb tcpip 6666
restarting in TCP mode port: 6666
3,连接手机
adb connect 设备ip:port
adb connect 172.0.0.218:6666
connected to 172.0.0.218:6666
进入终端,输入:adb devices
adb devices
List of devices attached
172.0.0.218:6666 device
手机解锁
数字密码
如图配置好,点击start session即可
连接成功,定位解锁图标
输入密码并确认
from appium import webdriver
desired_caps = {
'platformName': 'Android',
'deviceName': '52ec8347',
'platformVersion': '8.0',
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 点击解锁图标
driver.find_element_by_id('com.android.systemui:id/lock_icon').click()
password = '123456'
# 点击数字密码
for i in password:
num_xpath = f'//android.view.ViewGroup[@content-desc="{i}"]/android.widget.TextView'
driver.find_element_by_xpath(num_xpath).click()
# 点击确认
driver.find_element_by_xpath('//android.widget.ImageButton[@content-desc="输入"]').click()