使用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()