# How to get text from specific column and row in table

**URL:** <https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [December 6, 2019, 5:29pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243 "2019-12-06T17:29:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![krista.strzeszkowski](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@krista.strzeszkowski](https://forum.katalon.com/u/krista.strzeszkowski)\
**Post date:** [December 6, 2019, 5:29pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/1 "2019-12-06T17:29:48Z")

</div>

[https://docs.katalon.com/katalon-studio/docs/handle\_web\_tables.html](https://docs.katalon.com/katalon-studio/docs/handle_web_tables.html)  
I used this document to go through my webpage, there are several tables on my page and when I tried to find the specific table I tried to change  
`WebElement Table = driver.findElement(By.xpath("//table/tbody"))`  
to  
`WebElement Table = driver.findElement(By.id("dtgDetails"))`  
to find the specific table i needed on my page but this did not work.

I let the boilerplate code run until it found the piece in the table that I need and from however it maps the tables I found that the info I need is Row 141 and Column 5.

Is there a way that I can just say `find Table` `getText from row 141 and column 5` ?

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [December 6, 2019, 6:36pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/2 "2019-12-06T18:36:14Z")

</div>

> [@krista.strzeszkowski](#):
>
> Is there a way that I can just say `find Table` `getText from row 141 and column 5` ?

Tables are represented by HTML elements, just like buttons, dropdowns, menus, etc., are also HTML elements. Because HTML is code written by people, and every person has a unique way of writing code, there’s no way to implement something like findTable() or getText(row x, column y) that will be a “one size fits all” solution.

That’s why Katalon (and the underlying Selenium) can’t offer a clickButton() method or a getCellText() method. Instead, the more generic click() and getText() methods exist, and _you as the programmer must tell these methods which elements to perform the work on_.

If you can share the HTML for the table you are working with, I can work with you on a way to get the text you want from your (probably custom/unique) table.

---

<div class="post-metadata">

**Author:** ![krista.strzeszkowski](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@krista.strzeszkowski](https://forum.katalon.com/u/krista.strzeszkowski)\
**Post date:** [December 6, 2019, 7:01pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/3 "2019-12-06T19:01:50Z")

</div>

![tempsnip](https://europe1.discourse-cdn.com/katalon/original/2X/2/27d96e5a6eaeb75ab788ffd3371509da8e203244.png)

(I wanted to get rid of some information, like the town but otherwise these are not real addresses)

I am looking for the tracking number which is the really long circled number. If I inspect this page the 4 entries make up one table with `id = dtgDetails` and then every value is one table as well

 ![Capture1](https://europe1.discourse-cdn.com/katalon/original/2X/7/7af3076d86619d5bd39e9c8871833d2557b3dfaf.jpeg)  
and the HTML looks like this so `class="resultsTable"`is one row of the big table and I want to find the `headerPIC3` under the `class="resultsNumbering">1` ![Capture2](https://europe1.discourse-cdn.com/katalon/original/2X/f/f5537f5b9e1e13dd9b51dfa15503251b6f23745c.jpeg)  
the tracking number is `td class='headerPIC3'` but the thing that confuses me is that every one of the tracking numbers is under the class `headerPIC3` and the actual value is outside.  
 ![Capture](https://europe1.discourse-cdn.com/katalon/original/2X/9/939dfa5b986a3485c356e89acae767c1008576fa.jpeg).

I know this is kind of messy, ideally I would like to be able to hover over the source code and highlight the piece I am looking for to show you but I do not know how to do that and use the snipping tool at the same time. Please let me know if I need to provide more information. Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [December 6, 2019, 8:07pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/4 "2019-12-06T20:07:38Z")

</div>

Wow, nested tables, everyone’s favorite 😅 This pretty much proves the point in my original response. There’s no way to handle this in a generic way that would work for everyone, so lets work on a custom solution.

I’ll suggest just a solution to get the tracking number for a given row, as identifying a row won’t be too hard, and finding any element within a row is relatively straight forward. But your idea of row AND column gets tricky with nested tables, because there’s no clear definition of _what a column is_ with that setup.

The heart of the solution is going to be your locator. I can suggest an xpath, but I’d like to do it in pieces and you can tell me if they make sense:

1.) **Locate the “results table”:**

`//table[@class='resultsTable']`

That should identify this piece:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/b/bb342afae517a776ab1c32764fc6fad6f0cb8158.png)

2.) **Within the “results table”, locate the appropriate row:**

`//table[@class='resultsTable']/tbody/tr[${rowIndex}]`

This should identify (depending on the value you’ll provide for “rowIndex”) these:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/7/70b19c60e136b085abbf4e40cb3aad4b5417ac6c.png)

3.) **Within the appropriate row, locate the tracking number:**

`//table[@class='resultsTable']/tbody/tr[${rowIndex}]//td[@class='headerPIC3']/a`

Which should locate the actual numbers, as long as there’s one (and only one) td[@class=‘headerPIC3’] element per row.

4.) **Create a test object with that xpath, then call it in your script:**

```
def rowIndex = 1 // this will grab the tracking number for the first row
def trackingNumber = WebUI.getText(findTestObject('path/to/test/object', ['rowIndex' : rowIndex]))

```

If this works for you, you could create similar test objects for the other elements in the table that you might want to retrieve the text for (Recipient Address, etc.). Give this a try, and let me know if you need anything clarified 🙂

---

<div class="post-metadata">

**Author:** ![krista.strzeszkowski](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@krista.strzeszkowski](https://forum.katalon.com/u/krista.strzeszkowski)\
**Post date:** [December 9, 2019, 6:45pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/5 "2019-12-09T18:45:26Z")

</div>

Hi, I have just gotten to work and I am back looking at the test case!!

The thing I am most confused with is creating the object, `//table[@class='ResultsTable']/tbody/tr{$rowIndex}]/td[@class='headerPIC3']/a `  
this path is supposed to be in the ‘Selected Locator’ box and the ‘Selection Method’ should be ‘xPath’, I know for other objects I have needed to find and have spied on Katalon maps then and uses objects that are nearby under ‘Object’s Xpaths’..(right?) so is there anything I am missing in creating this object?? I tried the fix but I think I might be missing something because it still is not working.

 ![path](https://europe1.discourse-cdn.com/katalon/original/2X/f/fb6561394f71d04c9b2360f1c77e1dfbbc53e5ff.jpeg)  
I also am kind of confused because when I run this I see that ![fix1](https://europe1.discourse-cdn.com/katalon/original/2X/a/a3e9f1676d8d4535bb8ade176867fc5f0eb25ca9.jpeg) the test errored but I do not see a console so I do not see the error…

Thank you so much for your help and patience!

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [December 9, 2019, 7:33pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/6 "2019-12-09T19:33:16Z")

</div>

Your test object should look like this:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/0/0917db7342b84b7b732b461de202becd0b791a73.png)

Please ensure the following:  
1.) Selection Method = “Attributes”  
2.) Add an Object Property with Name = “xpath” and value = “//table[@class=‘ResultsTable’]/tbody/tr{$rowIndex}]/td[@class=‘headerPIC3’]/a”  
3.) Make sure the “Detect object by?” checkbox is selected for the xpath.

---

<div class="post-metadata">

**Author:** ![krista.strzeszkowski](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@krista.strzeszkowski](https://forum.katalon.com/u/krista.strzeszkowski)\
**Post date:** [December 10, 2019, 2:21pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/7 "2019-12-10T14:21:09Z")

</div>

I am still just having trouble locating the object, everything I have tried comes back with ‘object does not exist’. 😢

 ![erroe123](https://europe1.discourse-cdn.com/katalon/original/2X/6/62d4e156283594ecdc9183dddc465593a0a1fb7d.jpeg)  
I tried to spy on the tracking number but that did not work.  
 ![stillerror](https://europe1.discourse-cdn.com/katalon/original/2X/4/42bc731ab65fe7477b3291491233276dc8ab8156.jpeg)  
I tried another test with this object and this is the error  
 ![newpic](https://europe1.discourse-cdn.com/katalon/original/2X/7/76f8a66219e9b5a1f9cb22a831bc0eb358891fae.jpeg)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 10, 2019, 3:06pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/8 "2019-12-10T15:06:07Z")

</div>

Krysta

Go back over your code, _very carefully_. A simple typo crept in somewhere…

You want…

## `${rowIndex}`
  

not `{$rowIndex}`

---

<div class="post-metadata">

**Author:** ![krista.strzeszkowski](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@krista.strzeszkowski](https://forum.katalon.com/u/krista.strzeszkowski)\
**Post date:** [December 10, 2019, 3:48pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/9 "2019-12-10T15:48:36Z")

</div>

Oh boy, 😅

Thank you so so so much for all your help! Got it!!!

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 10, 2019, 3:57pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/10 "2019-12-10T15:57:22Z")

</div>

Closed on December 10, 2019, 3:57pm UTC



---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [December 10, 2019, 4:04pm UTC](https://forum.katalon.com/t/how-to-get-text-from-specific-column-and-row-in-table/37243/11 "2019-12-10T16:04:41Z")

</div>

Hi krista,

We’re you able to get the text as expected? It looks like the errors you were sharing were an issue locating your custom test object in the object repository (nothing to do with finding the element on the page itself, this is a separate error altogether).
