Data Extraction of Table Format from Web

Good morning, everyone!
I need to extract data from the web. And compare the data that I searched for, for example, if I searched for a particular name, I want to see if the data given below is the same data that I searched for, and if so, how can I extract the entire column from the web? The data is presented in the form of a table.


You have probably read the below information on web tables,

How to handle Web Tables in Katalon Studio | Katalon Docs

but you can also use parameterized Test Objects of the table and using WebUI statements.

Manage Web test objects in Katalon Studio | Katalon Docs

As an example, with a Keyword you can create a Test Object like:

TestObject cellVar = com.Tools.makeTO('//table/tbody/tr[2]/td[3]')

And of course, the row position can be a variable that you set; same as the column position, like:

"//table/tbody/tr[${rowPos}]/td[${colPos}]" and have all sorts of fun with that.

Parameterize Web Test Objects in Katalon Studio | Katalon Docs

Keyword you may want to use
public class Tools {

	// helper function that creates a new TestObject with xpath
	static TestObject makeTO(String xpath) {
		TestObject to = new TestObject(xpath)
		to.addProperty('xpath', ConditionType.EQUALS, xpath)
		return to

Can you Tell me How to Pass 2 Variables in Single Selector just like you means how to assign Values Can you give me the Syntax ??

There are two ways that come to mind. One method that I have used is in a double for loop, like:

for (rowPos = 1; rowPos <= 5; rowPos++) {
    for (colPos = 1; colPos <= 3; colPos++) {
        cellItem = driver.findElement(By.xpath("//table/tbody/tr[${rowPos}]/td[${colPos}]"))
        if (cellItem.getText() == "givenTextToFind") {

You don’t need to have a double for loop, but you do need to supply a value for both variables, like:

rowPos = 1
colPos = 3
xpath = "//table/tbody/tr[${rowPos}]/td[${colPos}]"
TestObject objItem  = new TestObject(xpath)
objItem.addProperty('xpath', ConditionType.EQUALS, xpath)

The other way is to have the xpath as part of an element in the Object Repository and then supply two values for both of the variables. So in the OR, you would have your element, as an example with name like 'myPage/span_General.TableCell' which has an xpath like //table/tbody/tr[${rowPos}]/td[${colPos}]/span and then you can have in your Test Case, an example like:

cellText = WebUI.getText(findTestObject('myPage/span_General.TableCell', 1, 3))

in the above statement, the 1 would be for the value of “rowPos” and the 3 would be for the value of “colPos”.

See if that works.

1 Like