Python+Appium自动化测试-4:自动启动APP后权限选择实现

使用Appium启动APP后会出现禁止和始终允许两种权限选择,可以通过text文本定位,并点击对应的选择。代码实现如下:

# -*- coding: utf-8 -*-
# @Author   : cjn
# @FILE     : APKAuthority.py
# @Time     : 2020/4/14 13:18
import time
from appium import webdriver

desired_caps = {
  "appPackage": "com.skylight.publiccloud",
  "appActivity": "com.skylight.publiccloud.WelcomeActivity",
  "platformName": "Android",
  "platformVersion": "9",
  "deviceName": "Honor9"
}

driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)

time.sleep(5)

flag = True
def select():
    if flag == True:
        choice = driver.find_element_by_xpath("//android.widget.Button[contains( @ text ,'始终允许')]")
        choice.click()
    else:
        choice = driver.find_element_by_xpath("//android.widget.Button[contains( @ text ,'禁止')]")
        choice.click()

if __name__ == "__main__":
    select()

你可能感兴趣的:(Appium)