Cannot convert value of type 'XCUIElement.Type' to expected argument type 'XCUIElement.Type'

Hello, I encounter a problem with the error message as in a title, during migration from Swift 3.2 to Swift 4 with our UI automated tests project. I have a couple of helper methods for XCUIElement, some of them were taking XCUIElementType as param type.


Since Swift 4 all occurrences of XCUIElementType were changed to `XCUIElement.Type` and now when I try to use it I get error message:


Cannot convert value of type 'XCUIElement.Type' to expected argument type 'XCUIElement.Type'

example method:


extension XCUIElement {
    func containing(identifiers: [String], type: XCUIElement.Type) -> Bool {
        for i in 0 ..< identifiers.count {
            if !self.descendants(matching: type).matching(identifier: identifiers[i]).element.exists { return false }
        }
        return true
    }
}

Error is thrown here in line 5, in 'self.descendants(matching: type)' (the type is underlined)


I checked it and when I do 'Jump to definition' sometimes I can see that XCUIElement has enum with name Type.

Correct me if I'm wrong but Xcode thinks as it is actual meta type of XCUIElement, it does not see it as an enum.


I'm using Xcode Version 9.0 (9A235) (updated via AppStore)

I will be more than grateful if someone helps me get rid of this error. The current workaround is staying with Swift 3.2 for UI tests.


Accepted Reply

laikkk,


I solved this by enclsing Type with back quotes `Type`.


func containing(identifiers: [String], type: XCUIElement.`Type`) -> Bool { ...


let anyType: XCUIElement.`Type` = .any

Replies

I have a problem relating to what appears to be the same issue you have:


Entering the following code:

let anyType = XCUIElement.Type.any


Gives the error: Type XCUIElement.Type has no member 'any'

laikkk,


I solved this by enclsing Type with back quotes `Type`.


func containing(identifiers: [String], type: XCUIElement.`Type`) -> Bool { ...


let anyType: XCUIElement.`Type` = .any

Thanks 🙂 it start compiling 🙂!