Hi, I am on Katalon Studio v8.6.8 and been working on a script that works on a table. It is working until there is a UI change and need to update the xpath for the table, which I already did. It is working for couple of weeks. Then it fails, the script needs to count the rows and return the no. of rows for a certain logic but it seems it only returns 1 or 0 and sometimes it returns the correct no. of rows. It is just failing locally but when it is executed on bamboo / server it is passing without failures. Do you have any idea what might causes this? Thanks!
This is the keyword I am using to get the row count. Hope this helps!
Hi there,
Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.
Thanks!
I had problems with some tables because I did not give my script enough time for the table to properly finish forming. My script would keep âblowing upâ. What I did was to put in a âwaitâ statement until a cell in the first data line was visible. Note, not a header line (i.e <th>
, but a data line <td>
.
Secondly, your Keyword needs the final line to be âreturn numRowsâ, like
def Integer getHtmlTableRows(TestObject table, String outerTagName) {
WebElement mailList = WebUI.findWebElement(table)
List<WebElement> selectedRows = mailList.findElements(By.xpath(outerTagName + "/tr"))
int numRows = selectedRows.size()
return numRows
}
Edit: or you can just return the âsizeâ, like:
List<WebElement> selectedRows = mailList.findElements(By.xpath(outerTagName + "/tr"))
return selectedRows.size()
Actually, it doesnât need a return statement.
ââSee 3.2.1 Method definition
At a glance, his code looks fine. However, for clarity, adding an explicit return statement is arguably the better practice.