How to read data from a dynamic table

please post example how to read data from a dynamic table and click on a hyperlink from the table

1 Like

Thanks Nilau.

unable to find the element on the page because it take some 30-40 sec to load the data after clicking on the Search button. For that I have written the code as below.

String ExpectedValue = ‘07012019’

WebDriver driver = DriverFactory.getWebDriver()

‘To locate table’

WebElement Table = driver.findElement(By.xpath(’//table[@id=tableENF123Submissions]/tbody/tr/td/a’))
WebUI.waitForElementPresent(ExpectedValue, 30)
'To locate rows of table it will Capture all the rows available in the table ’

List Rows = Table.findElements(By.tagName(‘tr’))

println('No. of rows: ’ + Rows.size())

‘Find a matching text in a table and performing action’

‘Loop will execute for all the rows of the table’

table: for (int i = 0; i < Rows.size(); i++) {

‘To locate columns(cells) of that specific row’

List Cols = Rows.get(i).findElements(By.tagName(‘td’))

for (int j = 0; j < Cols.size(); j++) {

‘Verifying the expected text in the each cell’

if (Cols.get(j).getText().equalsIgnoreCase(ExpectedValue)) {

‘To locate anchor in the expected value matched row to perform action’

Cols.get(1).findElement(By.tagName(‘a’)).click()

table: break

}
}
}
Error Logs:
2019-08-12 10:50:20.108 DEBUG testcase.ENF-08 - 10: Table = driver.findElement(By.xpath("//table[@id=tableENF123Submissions]/tbody/tr/td/a"))
2019-08-12 10:50:20.120 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/ENF-08 FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: By for class: Script1565629742454
at ENF-08.run(ENF-08:41)

Thanks

Hi,
Add

import org.openqa.selenium.By as By
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

Thanks Helen for your response. It is fixed after giving the webui.delay and after making some changes in the for loop.

please help me to create a class for reading the data from the excel sheet and create a for loop like for(int i=1; I<=exceldata.getRowNumbers(); i++).

Thanks

prakash

If you can’t code a loop, don’t use it.
Use Data Driven on Test Suite, Katalon will do the loop for you

thanks Helene…and working as expected now :slight_smile:

Hi Can you please share your successful code i am having the same test case.?

for (int rowNum = 1; rowNum <= findTestData(‘LocationNameID’).getRowNumbers(); rowNum++) {
WebUI.setText(findTestObject(‘Form Search/input_Location ID or Name_LocIdSearchString’), findTestData(‘LocationNameID’).getValue(1, rowNum))

WebUI.click(findTestObject('Form Search/button_Search'))

WebUI.delay(10)

//String ExpectedValue = '34816-01'

String ExpectedValue = findTestData('LocationNameID').getValue(2, rowNum)

WebDriver driver = DriverFactory.getWebDriver()

WebUI.delay(10)

WebElement Table = driver.findElement(By.xpath('//table[@id=\'tableLocations\']/tbody'))

List<WebElement> links = Table.findElements(By.xpath('//tr/td'))

for (int j = 0; j < links.size(); j++) {
    'Verifying the expected text in the each cell'
    if (links.get(j).getText().equalsIgnoreCase(ExpectedValue)) {
        'To locate anchor in the expected value matched row to perform action'
        links.get(j).click()

        WebUI.delay(5)

        WebUI.verifyElementPresent(findTestObject('Form Search/h2_Filing History'), 0)

        break
    }
}