Appium+python Automation 47-opening app permissions for the first time popup issue

Source: Internet
Author: User
Tags xpath appium

Objective

Run the Appium code with the real machine, the first time you open the app, some phones will have permission pop-up window problem, usually this pop-up window is in front of the boot page or after the boot page appears. The buttons on the right pop-up window are fixed,
Just navigate to the "Always Allow" button and click OK. There is another problem is that the number of pop-up windows are not certain, some apps are 2 or 3, in order to solve this problem, you can write a judgment method.
Note: The emulator does not have this permission pop-up window

Environment:
Appium 1.8
Android 7.0
American Group App

Permission pop-up window

1. In the case of the American Group app, when the app is first launched, a permission pop-up box appears on the boot page, such as this

2. This kind of pop-up window can be directly located, and here can not be located through the ID, because more pop-up windows, each time the ID is not the same, but the text is the same: always Allow

Positioning System pop-up window

1. Use XPath to position the button: always Allow

LOC = ("XPath", "//*[@text = ' Always Allow ']")

2. Use the selenium inside the display waiting module (webdriverwait) and the Judgment Module (expected_conditions) Packaging positioning method, before the Selenium tutorial in detail, here will not repeat the

From Selenium.webdriver.support.ui import webdriverwait
From Selenium.webdriver.support import expected_conditions as EC

# 判断是否有权限弹窗for i in range(5):    loc = ("xpath", "//*[@text=‘始终允许‘]") try: e = WebDriverWait(driver, 1, 0.5).until(EC.presence_of_element_located(loc)) e.click() except: pass

3. Write a separate function, encapsulating the system permissions to judge the popup window, before the use case before the call can be

Reference Code
#Coding:utf-8 fromAppiumImportWebdriver fromSelenium.webdriver.support.uiImportwebdriverwait fromSelenium.webdriver.supportImportExpected_conditions as ECImportOSImportTimepath=LambdaX:os.path.join (Os.path.dirname (Os.path.realpath (__file__) ), X)#Baidu Download an American group app, put the current script in the same directoryPrint(PATH ('meituan_626.apk')) Desired_caps= {                'PlatformName':'Android',                'devicename':'127.0.0.1:62001',                'platformversion':'7.0',                'app': PATH ('meituan_626.apk'),                'Apppackage':'Com.sankuai.meituan',                'appactivity':'Com.meituan.android.pt.homepage.activity.Welcome',                'NoReset':'true',                #' resetkeyboard ': ' True ',                #' unicodekeyboard ': ' True '}driver= Webdriver. Remote ('Http://127.0.0.1:4723/wd/hub', Desired_caps) time.sleep (3)defAlways_allow (Driver, number=5):    " "fuction: Permission popup-Always allow args:1. Driver 2.number, judging the number of pop-up windows, default to 5 times other: Webdriverwait inside 0.5s To determine if there is a pop-up window, 1s timeout" "     forIinchRange (number): Loc= ("XPath","//*[@text = ' Always Allow ']")        Try: E= Webdriverwait (driver, 1, 0.5). Until (ec.presence_of_element_located (Loc)) E.click ()except:            Passif __name__=="__main__":    #call always allow functionAlways_allow (Driver)

Appium+python Automation 47-opening app permissions for the first time popup issue

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.