How to read data from a dynamic table


#1

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


#2

#3

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


#4

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

#5

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


#6

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


#7

thanks Helene…and working as expected now :slight_smile: