Selenium WebDriver code to select multiple elements on page from Katalon Studio

Much to my delight, I found out that you can use Selenium WebDriver in Katalon Studio. (Just say:

WebDriver driver = DriverFactory.getWebDriver()

the navigation to URL. )

However, the support seems a bit…buggy. My use case is this:

I have a named

    element, inside which are
  • elements that I am trying to get into a list.

    The HTML code I am trying to put under test contains this:

    <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>my Selenium code looks like this : // Loop over selection of each company, and assert that we land on respective dashboarddriver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS)WebElement companyListContainer = driver.findElement(By.id('companyList')) // seems to find this element OKList<WebElement> companies = companyListContainer.findElements(By.xpath('.//li')) // this failedfor (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)}How do I fix this? (If I cannot, then Katalon Studio is useless to me.)
    

Michael,

I found a bug in your test case:

List<WebElement> companies = ...for (int i = 1; i <= companies.length; i++) {

java.util.List object does not have a length property.

You should write:

List<WebElement> companies = ...for (int i = 1; i <= companies.size(); i++) {
2 Likes

Ya, silly me…