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

Your Answer

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

Browse other questions tagged or ask your own question.