I am writing automation tests for an iOS App, where it requires access to ‘Select Photos…’, ‘Allow Access to All Photos’, and ‘Don’t Allow’. I am using Appium 2.0 with Webdriver.io, running on BrowserStack with an iOS 16.3 device.
Initially, I used the
‘name’
locator strategy for the
'Allow Access to All Photos
’ button, as it is unique. It worked for a couple of times and then started failing intermittently. When I checked the execution video, it’s actually clicking the ‘Don’t Allow’ button.
So, I changed the locator strategy to use the iOS Predicate as follows:
type == “XCUIElementTypeButton” AND label == “Allow Access to All Photos” AND name == “Allow Access to All Photos”
. However, it still fails intermittently with the error: "Error: element ("-ios predicate string:type == "XCUIElementTypeButton" AND label == "Allow Access to All Photos" AND name == "Allow Access to All Photos"") still not displayed after 10000ms"
, but it’s actually clicking the ‘Don’t Allow’ button in the video.
This is the block of code I am using:
const allowAccessToAllPhotosButton = await this.allowAccessToAllPhotosButton; await allowAccessToAllPhotosButton.waitForDisplayed(); await allowAccessToAllPhotosButton.click();
get allowAccessToAllPhotosButton(): Promise<WebdriverIO.Element> {
return getElementByPredicate(IOSPredicate.ALLOW_ACCESS_TO_ALL_PHOTOS_BUTTON);
}