from appium import webdriver desired_caps = {} # 系统 desired_caps['platformName'] = 'Android' # 版本 desired_caps['platformVersion'] = '6.0' # 设备号 desired_caps['deviceName'] = 'LE67A06300301948' # 包名 desired_caps['appPackage'] = 'com.android.settings' # 启动名 desired_caps['appActivity'] = '.Settings' # 声明手机驱动对象 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) # 关闭APP driver.close_app() # 启动其他APP driver.start_activity('com.android.dialer', '.DialtactsActivity')# 安装APP driver.install_app('C:\\Users\\Administrator\\Desktop\\Phone.2.8.7.apk') #卸载APP driver.remove_app('包名') # 判断是否安装了APP if driver.is_app_installed("包名"): driver.remove_app("启动名") else: driver.install_app("C:\\Users\\Administrator\\Desktop\\Phone.2.5.8.apk") # 发送文件到手机 import base64 data = "push 123456push 123456push 123456push 123456push 123456" data = str(base64.b64encode(data.encode("utf-8")), "utf-8") driver.push_file("/sdcard/a.txt", data) # 从手机上取文件 import base64 data = driver.pull_file("/sdcard/a.txt") print(str(base64.b64decode(data), "utf-8")) # 获取页面元素 data = driver.page_source for i in ("蓝牙", "WLAN", "账户"): if i in data: print(True) else: print(False) # 退出手机驱动对象 driver.quit()