Java-client: List element annotation unsupported for kotlin

Created on 23 Oct 2019  路  2Comments  路  Source: appium/java-client

Description

Hi, i have an element as annotation in List of WebElement/MobileElement code below

image

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:

Most helpful comment

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>

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings