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