python - 如何在 iOS Appium 上按 "OK"弹出位置

标签 python ios mobile automation appium

我正在尝试自动化我的移动网络应用程序。每次加载时,它都会询问“___ 想使用您的位置”。用户可以点击“不允许”或“确定”。

我正在使用 self.driver.switch_to.alert.accept(),但它接受默认值,即“不允许”。如何接受“OK”而不是“不允许”?

最佳答案

该方法目前对我也不起作用。

您是否尝试使用 Appium Inspector 定位“确定”按钮? 我有相同的位置弹出窗口,对我来说,这些在 iOS 上都有效(xpath 或辅助功能 ID)。

类似于:

allow_access_to_location_ios = (MobileBy.ACCESSIBILITY_ID, 'OK')

allow_access_to_location_ios = (MobileBy.XPATH, '//XCUIElementTypeButton[@name="OK"]')

然后调用方法:

self.wait_for_and_accept_alert(*self.allow_access_to_location_ios)

方法将等待该元素 15 秒,如果找到它则单击它,否则它会打印一条错误消息:

def wait_for_and_accept_alert(self, *locator):
    try:
        WebDriverWait(self.driver, 15).until(lambda s: self.driver.find_element(*locator))
        self.driver.find_element(*locator).click()
    except TimeoutException:
        print('Unable to find element')

关于python - 如何在 iOS Appium 上按 "OK"弹出位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50842653/

相关文章:

Python异常KeyError问题

python - 如何在 Tensorflow 中使用多个模型

python - 如何在 PyPy 中导入 .so 模块?

iphone - iOS - MPMediaPickerController - 更改 barStyle

javascript - 从浏览器中禁用 iOS 双击空格键

url - 我应该在 robots.txt 中包含移动网站 URL 吗?

python - 在 Tensorflow 中使用 BigQueryReader 读取数据

ios - 如何在 iOS 中使用 Swift 格式化字符串?

ios - 如何在iOS中以字母开头的数组元素的索引?

mobile - Swiper 幻灯片 - 显示上一张/下一张幻灯片的结束/开始,例如 Airbnb Slider?