0

I'm building a selenium test using a POM, and I have a List of Webelements (companyNames in SelectAccountPage) that keeps throwing a UninitializedPropertyAccessException.

Here's the Page Object

class SelectAccountPage(driver: WebDriver) {

@FindBy(css = "header h2")
lateinit var selectAccountTitle: WebElement

@FindBy(css = "div[class*='company-picker'] h3")
lateinit var companyNames: List<WebElement>

init {
    PageFactory.initElements(driver, this)
}

fun pickCompany(companyToSelect: String) {
    for (company in companyNames) {
        if (company.text == companyToSelect) {
            company.click()
        }
    }
}

and the test

class SignInTest : TestBase() {

    lateinit var signInPage: SignInPage
    lateinit var forgotPasswordPage: ForgotPasswordPage
    lateinit var selectAccountPage: SelectAccountPage

    @BeforeTest
    fun initPageObjects() {
        signInPage = SignInPage(driver)
        forgotPasswordPage = ForgotPasswordPage(driver)
        selectAccountPage = SelectAccountPage(driver)
        assert = SoftAssert()
    }

   @Test(priority = 3)
    fun validCredentials() {
        driver.get(signInPage.url)
        signInPage.sendCredentials(Config.getUser(), Config.getPassword())
        assert.assertTrue(driver.currentUrl.contains("app"))
        selectAccountPage.pickCompany("Generic")
        assert.assertAll()
    }

I'm not sure what's going on here because the Webelement on the same page is initialized just fine. Is there something specific that needs to be done when initializing Lists?

2

2 Answers 2

0

You most probably already found an answer, but I am leaving it just in case somebody else came across this problem, as I did to today.

@FindBy(css = "div[class*='company-picker'] h3")
val companyNames: List<WebElement>? = null

Changing code as above did the trick for me.

0

Use MutableList instead of List

so you will have:

lateinit var companyNames: MutableList<WebElement>

1
  • 1
    Could you please edit this answer to explain why MutableList<WebElement> will work better for the OP than List<WebElement>.
    – Kate Paulk
    Oct 18, 2022 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.