问题描述: 在iOS 14上,使用Appium的autoAcceptAlert方法无法起作用,无法自动允许访问所有照片的弹窗。
解决方法:
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.extensions.xcode import XcodeOrg
desired_caps = {
'platformName': 'iOS',
'platformVersion': '14.0',
'deviceName': 'iPhone 11',
'automationName': 'XCUITest',
'app': 'path/to/your/app'
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 创建XcodeOrg对象
xcode_org = XcodeOrg()
# 使用XcodeOrg对象来处理弹窗
xcode_org.resolve_alert()
# 在此之后可以继续执行其他操作
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
desired_caps = {
'platformName': 'iOS',
'platformVersion': '14.0',
'deviceName': 'iPhone 11',
'automationName': 'XCUITest',
'app': 'path/to/your/app'
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 使用mobile: acceptAlert命令来处理弹窗
driver.execute_script('mobile: acceptAlert')
# 在此之后可以继续执行其他操作
在以上两种方法中,第一种方法使用了xcode-org模块来处理弹窗,第二种方法使用了mobile: acceptAlert命令来处理弹窗。您可以根据自己的需求选择适合您的方法。