java-client
java-client copied to clipboard
List element annotation unsupported for kotlin
Description
Hi, i have an element as annotation in List of WebElement/MobileElement code below
in Java, i could access the element directly with the provided index. but in kotlin when i called the element with btnArrival0to6[1].click()
it throws
Method threw 'kotlin.UninitializedPropertyAccessException' exception.
Environment
- java client build version : 6.1.0
- Appium server version or git revision if you use some shapshot:
- Desktop OS/version used to run Appium if necessary:
- Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe:
- Mobile platform/version under test:
- Real device or emulator/simulator:
I don't think that it's the annotation that's incompatible entirely. You can use the same annotation to find a single (non-list) element just fine in Kotlin. The issue appears to come from the use of the Kotlin List instead of the Java List. Kotlin actively does not want you to use the Java List, and it complains if you do so.
However, using a typed ArrayList
seems to work fine for me. Try something like:
@AndroidFindBy(accessibility = "A")
@iOSXCUITFindBy(accessibility = "B")
private lateinit var btnArrival0to6: ArrayList<MobileElement>
Issue confirmed on io.appium:java-client:7.3.0. Workaround suggested by @stupergenius is still working.
Any idea why this happens? It's still happening in version 9.0.0
... but we were on 7.6.0
previously and it was not happening 🤔
It had us stumped for a couple of days until I found this issue... In our case, we're trying to iterate a List
and the loop just never executes... In the debugger it looked like it was related to something that the io.appium.java_client.proxy.Interceptor
is doing...
Stepping through the code and while the debugger could see that the list had a size of 5, the code would never go into the loop (for (element in elementsList)
)
Going to update to use ArrayList
now but would love to understand why this happens.