appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 755 forks source link

Cannot get list of Elements with Page Factory #1270

Open AliceCarroll239 opened 4 years ago

AliceCarroll239 commented 4 years ago

Description

@iOSXCUITFindBy(locator) List returns null, while driver.findElements(locator) return list

Environment

Details

Screenshot 2019-11-22 at 11 34 03

Code To Reproduce Issue [ Good To Have ]

//retun null @iOSXCUITFindBy(className = "XCUIElementTypeCell") var ordersList: List< MobileElement>? = null

init {
    PageFactory.initElements(AppiumFieldDecorator(driver), this)
}

//return list with 2 elements fun orders(): List? { return driver!!.findElements(MobileBy.className("XCUIElementTypeCell")) }

Exception Stacktraces

Link To Appium Logs

mlthlschr commented 4 years ago

I can confirm this behaviour, both in 7.2.0 as well as 7.3.0.

In 7.2.0 the type check of generics is not done at all. In 7.3.0: In my case the conditional statement in AppiumFieldDecorator fails, as the listType is a WildCardType, not a TypeVariable. In the end, also this Type contains an upper bound.

if ((listType instanceof TypeVariable)
        && Arrays.asList(((TypeVariable<?>) listType).getBounds())
        .stream().anyMatch(item -> availableElementClasses.contains(item))) {
    return true;
}