0

I am attempting to get all <li> in a specified <ul> in Katalon Studio. I am trying this via Selenium WebDriver. I have code like this :

// login with valid account
WebUI.callTestCase(findTestCase('ValidLogin'), [('shouldCloseBrowser') : false], FailureHandling.STOP_ON_FAILURE)

// get the driver
WebDriver driver = DriverFactory.getWebDriver()

// Loop over selection of each company, and assert that we land on respective dashboard
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS)

WebElement companyListContainer = driver.findElement(By.id('companyList')) 
// finds this element OK


List<WebElement> companies = companyListContainer.findElements(By.xpath('.//li'))
 // this failed

for (int i = 1; i <= companies.length; i++) {
    // click the test object
    driver.findElement(By.xpath('//ul[@id="companyList"]/li[' + i + ']')).click() 
    // implicitly wait 3 seconds
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS) // we better be at the Dashboard page
    // go back to "Company Select"
    WebUI.click(findTestObject('a_Company Select'))
    // wait three seconds again
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS)
}

and for some reason, even though there were <li>s on the page, the List<WebElement> is null, even though companyListContainer wasn't, and contained those elements. How do I fix this?

The HTML

looks like :

<ul id="companyList" class="list-group">

    <li class="list-group-item clickable " data--name="EzDine C2 - Michael" data--id="302">
        EzDine C2 - Michael
        <span class="list-check"><i class="fa fa-check text-success" aria-hidden="true"></i></span>
    </li>

    <li class="list-group-item clickable " data--name="EzDine Comp3 -Hos" data--id="303">
        EzDine Comp3 -Hos
        <span class="list-check"><i class="fa fa-check text-success" aria-hidden="true"></i></span>
    </li>

    <li class="list-group-item clickable " data--name="Test EZDine V2 Comp1" data--id="301">
        Test EZDine V2 Comp1
        <span class="list-check"><i class="fa fa-check text-success" aria-hidden="true"></i></span>
    </li>

</ul>
Mike Warren
  • 3,796
  • 5
  • 47
  • 99

1 Answers1

0

The error was because of the stupidest reason (that, somehow, Katalon failed to tell me): I was trying to access the length of a list; /* that member doesn't exist in java.util.List! */ I changed to size() and it worked.

Katalon is really flawed for not having alerted me of this; /* they said something about null not being defined, but not that I was attempting to access a member that didn't exist */

Mike Warren
  • 3,796
  • 5
  • 47
  • 99