Wait for element using begins with [Python/iOS] - Solved

Hello,

Can I wait for an element I don’t know its accessibility id yet?
Is it possible to use a starts-with expression on a wait?

After performing a search, the AUT will present a XCUIElementTypeStaticText, which’s name is: Result (x), x being the number of results returned.
I need to retrieve this element to proceed with the test.

I’ve managed to work around it by using a sleep, but I would like to have a more elegant solution, using an explicit wait.
This will find my element, but will fail if it hasn’t been loaded (thus, the sleep):
element = self.driver.find_element_by_ios_predicate(“type==‘XCUIElementTypeStaticText’ AND name BEGINSWITH[c] ‘Result’”)

I’ve tried these two options, none of them working:

self.wait.until(expected_conditions.presence_of_element_located((self.driver.find_element_by_ios_predicate(“type ==‘XCUIElementTypeStaticText’ AND name BEGINSWITH[c] ‘Result’”))))

self.wait.until(expected_conditions.presence_of_element_located((By.XPATH,"//input[@class=‘XCUIElementTypeStaticText’ and starts-with(@id, ‘Result’)]")))

Thanks,
Elias

Hello all,

I managed to get around this by creating a custom wait that checks for an element that begins with a given string and of a given type.

class element_begins_with(object):
#An expectation for checking that an element of a given type that begins with a given expression.
def init(self, type, string):
self.type = type
self.string = string

def call(self, driver):
element = driver.find_element_by_ios_predicate(“type ==’”+self.type+"’ AND name BEGINSWITH[c] ‘"+self.string+"’")

if element != None:
    return element
else:
    return False

Which is called as below:
element = self.wait.until(Util.element_begins_with(“XCUIElementTypeStaticText”, “Result”))

Any suggestions welcomed.

Thanks,
Elias