权限弹框无法点击到 每次到 el7 那里代码就运行不下去 类似最下面那种权限弹框

from appium import webdriver
import pytest
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By

class TestContact:

def setup(self):
    caps = {
        "platformName": "Android",
        "deviceName": "emulator-5444",
        "appPackage": "com.tencent.wework",
        "appActivity": ".launch.LaunchSplashActivity bnds",
        "autoGrantPermission": "ture",
        "noRest":"true",
        "dontStopAppOnRest":"true"
    }
    self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
def teardown(self):
    pass
def test_contact01(self):
    self.driver.implicitly_wait(200)
    el1 = self.driver.find_element_by_xpath("//*[@text='拒绝']")
    el1.click()
    el2 = self.driver.find_element_by_id("com.android.packageinstaller:id/permission_deny_button")
    el2.click()
    el3 = self.driver.find_element_by_id("com.tencent.wework:id/zw")
    el3.click()
    el4 = self.driver.find_element_by_id("com.tencent.wework:id/bz9")
    el4.click()
    el5 = self.driver.find_element_by_id("com.android.packageinstaller:id/permission_deny_button")
    el5.click()
    el6 = self.driver.find_element_by_xpath("//*[@text='拒绝']")
    el6.click()
    el7 = self.driver.find_element_by_xpath("//*[@text='拒绝']")
    el7.click()
    el8 = self.driver.find_element_by_xpath("//*[@text='拒绝']")
    el8.click()

if name == ‘main’:
pytest.main()

test_09.py::TestContact::test_contact01 FAILED [100%]
test_09.py:21 (TestContact.test_contact01)
self = <test_09.TestContact object at 0x0000024B51C47970>

def test_contact01(self):
    self.driver.implicitly_wait(200)
    el1 = self.driver.find_element_by_xpath("//*[@text='拒绝']")
    el1.click()
    el2 = self.driver.find_element_by_id("com.android.packageinstaller:id/permission_deny_button")
    el2.click()
    el3 = self.driver.find_element_by_id("com.tencent.wework:id/zw")
    el3.click()
    el4 = self.driver.find_element_by_id("com.tencent.wework:id/bz9")
    el4.click()
    el5 = self.driver.find_element_by_id("com.android.packageinstaller:id/permission_deny_button")
    el5.click()
    el6 = self.driver.find_element_by_xpath("//*[@text='拒绝']")
    el6.click()
    el7 = self.driver.find_element_by_xpath("//*[@text='拒绝']")
  el7.click()



image

你设置允许,先走后面的流程,后面有课程去讲怎么处理这一类的弹窗

怎么走流程啊 这里写不下去啊

你可能多点击了一个吧,因为前面的都可以点击,说明定位没问题。你可能碰巧定位到了上个快要消失的已点过的控件了

不是的 报错提示说的 dom文件里没有那个元素 可实际操作确实有那个弹框

你先加个try、except吧,如果元素存在,就去点,不存在就忽略(临时方案,不太好),因为这些授权可能在使用APP的过程中弹出,后面有课程去教,类似一个黑名单的逻辑,在找元素的过程中,如果目标元素找不到,捕获异常,再去遍历黑名单内的元素是否在当前页面,如果在,就去点掉;

你先手动点击允许,noRest设置为true,别卡在这里,先完成练习

noReset,参数错了