zoukankan      html  css  js  c++  java
  • App 启动后弹出权限窗处理

    这种弹窗是可以直接定位到的,这里不能通过id去定位了,因为弹窗比较多,每次id都不太一样,但是文本text都是一样的:始终允许

    from
    appium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import os import time

    1 通过xpath来定位按钮:始终允许

    
    

    loc = ("xpath", "//*[@text='始终允许']")

    
    

    2.用selenium里面的显示等待模块(WebDriverWait)和判断模块(expected_conditions)封装定位方法,之前selenium教程里面详细讲过,这里就不重复写了

    
    

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    
    
    PATH = lambda x: os.path.join(os.path.dirname(os.path.realpath(__file__)), x)
    
    
    print(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)
    
    def always_allow(driver, number=5):
        '''
        fuction:权限弹窗-始终允许
        args:1.传driver
        2.number,判断弹窗次数,默认给5次
        其它:
        WebDriverWait里面0.5s判断一次是否有弹窗,1s超时
        '''
        for i in range(number):
            loc = ("xpath", "//*[@text='始终允许']")
            try:
                e = WebDriverWait(driver,5, 0.5).until(EC.presence_of_element_located(loc))
                e.click()
            except:
                pass
    
    if __name__ == "__main__":
        # 调用始终允许函数
        always_allow(driver)
  • 相关阅读:
    .net core web
    ASP.NET HttpContext类
    页面周期与事件
    (49) C# npoi 读写office
    vs2017 vs2019秘钥
    HDU 2767 Proving Equivalences(强连通 Tarjan+缩点)
    【bzoj1013】[JSOI2008]球形空间产生器sphere
    P1979 [NOIP]华容道
    hdu4352 XHXJ's LIS(数位DP + LIS + 状态压缩)
    hdu3709 Balanced Number 树形dp
  • 原文地址:https://www.cnblogs.com/lexus168/p/13942583.html
Copyright © 2011-2022 走看看