锁屏

  1. self.driver.lock() # ---锁定屏幕(无限期锁定)
  2. self.driver.lock(秒数) # ---锁定屏幕(锁定固定秒数后自动解锁)
  3. self.driver.unlock() # ---解锁屏幕
  4. self.driver.is_locked() # ---判断屏幕是否已经被锁定,返回值是布尔值

输入法

  1. self.driver.deactivate_ime_engine() # 关闭当前输入法,会自动切换到安卓系统自带的输入法(.LatinIME)
  2. self.driver.is_ime_active() # 返回是否有输入法服务的布尔值。
  3. self.driver.available_ime_engines # 获得所有可用的输入法(引擎),返回一个列表,包含所有输入法引擎的字符串。
  4. self.driver.active_ime_engine # 获得正在使用的一个输入法(当前输入法)
  5. self.driver.activate_ime_engine("某一种输入法引擎") # 切换当前输入法为目标输入法

设备

  1. driver.quit()
  2. # 执行时,关闭DesiredCapabilities里所指定的目标App,不关闭其他App,结束与服务器的连接会话。

屏幕

  1. # 获取屏幕状态
  2. orientation = driver.orientation
  3. # LANDSCAPE 代表横屏
  4. # PORTRAIT 代表竖屏
  5. # 设置横竖屏
  6. driver.orientation = "LANDSCAPE" #设置为横屏
  7. driver.orientation = "PORTRAIT" #设置为竖屏

地理坐标

  1. # 设置地理坐标
  2. driver.set_location(x, y, h)
  3. 参数:
  4. 纬度-x number 所需的地理位置纬度
  5. 经度-y number 所需的地理位置经度
  6. 高度-h number 所需的地理位置高度(可选)
  7. # 获取当前地理坐标
  8. location=driver.location() # {'latitude': 50, 'longitude': 122, 'altitude': 8}

导入文件

  1. import base64
  2. # 目标文件路径
  3. dest_path = '/data/local/tmp/test_push_file.txt'
  4. # 文本中的内容和编码格式
  5. data = bytes('This is the contents of the file to push to the device.', 'utf-8')
  6. # 向目标路径导入文件
  7. driver.push_file(dest_path, base64.b64encode(data).decode('utf-8'))
  8. # 完成后结果
  9. C:\Users\lgq>adb shell
  10. vbox86p:/ # cd /data/local/tmp/
  11. vbox86p:/data/local/tmp # ls
  12. # appium_cache test_push_file.txt uidump.xml
  13. vbox86p:/data/local/tmp # cat test_push_file.txt
  14. # This is the contents of the file to push to the device.
  15. vbox86p:/data/local/tmp #

获取文件

  1. driver.pull_file('/data/local/tmp/test_push_file.txt')
  2. # ntYDG7Doz6+KfZpdepkGSjymTz/yysyDq2AaYzOLRPFtPZu0qQFBRpkMOxtWUabAuHb/IMngcSN0y4xaqaS+zUYnfj5lOGxizGTMAVuijc53Z

获取文件夹

  1. driver.pull_folder('/data/local/tmp/')

通知栏

  1. driver.open_notifications() # 无参,自动打开通知栏

开关WiFi

  1. driver.toggle_wifi() #当前开执行切换为关,当前关执行切换为开

开关定位

  1. driver.toggle_location_services() #当前开执行切换为关,当前关执行切换为开

发送短信(仅模拟器)

  1. driver.send_sms('17615146641', 'Hey')
  2. # 如果报错:sms method is only available for emulators
  3. # 说明你不是模拟器

打电话(仅模拟器)

  1. from appium.webdriver.extensions.android.gsm import GsmCallActions
  2. driver.make_gsm_call('5551234567', GsmCallActions.CALL)
  3. # 如果报错:gsmCall method is only available for emulators
  4. # 说明你不是模拟器