I am unsure why but no matter what I try, this doesn't seem to delete the entire text in the text field even when I inspect it and see the same number of delete characters as there are characters to delete. It's seemingly random and deletes different amounts of characters each iteration.
extension XCUIElement {
    /**
     Removes any current text in the field before typing in the new value
     - Parameter text: the text to enter into the field
     */
    func clearAndEnterText(text: String) {
        guard let stringValue = self.value as? String else {
            XCTFail("Tried to clear and enter text into a non string value")
            return
        }
        let deleteString = String(repeating: XCUIKeyboardKey.delete.rawValue, count: stringValue.count)
        self.typeText(deleteString)
        self.typeText(text)
    }
}
 
    