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>
` being a `.jobs` and the `- ` being the individual jobs? */
– Mike Warren Jun 13 '18 at 19:40