# Table dynamic Search

**URL:** <https://forum.katalon.com/t/table-dynamic-search/66577>\
**Category:** Web Testing\
**Tags:** web-testing\
**Created:** [July 5, 2022, 3:22am UTC](https://forum.katalon.com/t/table-dynamic-search/66577 "2022-07-05T03:22:09Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 2:31pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/23 "2022-07-18T14:31:24Z")

</div>

Just for your information, when you see code that is underlined by KS, then those variables have an issue; in this case, they are **undefined**. In other words, KS does not know what they are. In this case, they are undefined because you are missing the appropriate **import** statement. You can either hit CTRL + SHIFT + O (oh) to add the **import** statements automatically or add them manually, starting with:

```auto
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import org.openqa.selenium.By as By
import org.openqa.selenium.Keys as Keys
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement

import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory //this is the one you're missing
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

```

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 2:35pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/24 "2022-07-18T14:35:27Z")

</div>

> [@grylion54](#):
>
> Also, when you put code into this forum, put three back ticks, like ``` , above and below your code. The back tick is found on the same key as the tilde, like ~

Also, it would be easier to read your code if you put in the 3 back ticks like I said above.

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 18, 2022, 3:56pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/25 "2022-07-18T15:56:49Z")

</div>

Dear sir,  
With due respect I want to say ’ I love you sir’. Your code just worked nicely.

Sir I need one more thing. In this code I can click one value. What should I do if I want to check many check box at a time and those value will be given from an excel .

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 18, 2022, 4:00pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/26 "2022-07-18T16:00:25Z")

</div>

All I want sir  
I will search the value in the reference search box then the value will be highlighted. Then I will click the check box of highlighted row. And how can I give many value at a time from excel sheet and click the check boxes In that page. That page should not close after one selection.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 4:08pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/27 "2022-07-18T16:08:29Z")

</div>

You should make a loop that cycles through your code as many times as you need, or as many rows you have in your spreadsheet. You can find examples on this forum how to do that. Here is one example:

> [@Loop rows in Exel sheet](http://forum.katalon.com/t/loop-rows-in-exel-sheet/13557):
>
> Name Age Person 1&nbsp; &nbsp; &nbsp; 20 Person 2 21 Person 3 22 Person 4 23 How to loop this exel sheet data in katalon I have to fetch each Names and corresponding Ages using katalon How i can implement this in katalon

> [@sanjoy2016ewu](#):
>
> def requestedRef = ‘3193263’

For this statement , you would have to change it so that your spreadsheet is read instead, such as:

> [@Loop through excel file](http://forum.katalon.com/t/loop-through-excel-file/12287):
>
> The documentation for this was not much help, so in case somebody else searches for this hopefully this will help. First of all I created new test data file pointing at my excel file [Image: https://s3.amazonaws.com/katalon-forum/editor/gr/0zyvsxk27bzp.png] Then I looped through printing out the names using the following code in my test case import static com.kms.katalon.core.testdata.TestDataFactory.findTestData TestData data = findTestData('mydata') for (def index : (0..data.getRowNumbers(…

> [@Read Test Data from Excel](http://forum.katalon.com/t/read-test-data-from-excel/25229/3):
>
> Thanks Timo for your help!!! I was using findTestData( ) and getValue( ) methods from katalon studio API. below is snippet: WebUI.setText(findTestObject('Object Repository/Page\_Login Salesforce/input\_Username\_username'), findTestData('Automation Test Data').getValue( 'UserName', 1)) WebUI.setEncryptedText(findTestObject('Object Repository/Page\_Login Salesforce/input\_Password\_pw'), findTestData('Automation Test Data').getValue( 'Password', 1)) If I have to…

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 5:02pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/28 "2022-07-18T17:02:44Z")

</div>

Here is another reply on how to highlight your cell. Instead of label, you will give the pathway to your cell (at least you can try it).

> [@Verifying a label and wanted to hightlight with a color](http://forum.katalon.com/t/verifying-a-label-and-wanted-to-hightlight-with-a-color/32347/4):
>
> Try this: public class Highlight { /\*\* \* Highlight an element for five seconds using JavaScript. \* @param selector (String) The CSS selector for the element. \*/ @Keyword public static void highlightElement(String selector) { // Triple-quoted string containing JavaScript String js = ''' function highlightElement(selector) { $(selector).css("box-shadow", "1px 1px 4px 4px yellow, -1px -1px 4px 4px yellow"); setTimeout(function() { $(selecto…

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 5:06pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/29 "2022-07-18T17:06:37Z")

</div>

> [@sanjoy2016ewu](#):
>
> Is any need to count the row s?

I count the rows so that I can form an easy **for** loop. The alternative is to create a **while** loop and then you need to have **exit** conditions.

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 18, 2022, 5:22pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/30 "2022-07-18T17:22:45Z")

</div>

Sir I am little bit confused . Should I change the code.  
Then what will be the code. Please can you give the code where I have to bring change in code for many data from excel ?

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 5:25pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/31 "2022-07-18T17:25:11Z")

</div>

How about taking some time to review the links I gave you, first?

You can Save your code to your desktop, or some repository, but if you want your code to do more, then you will have to change it.

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 18, 2022, 5:33pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/32 "2022-07-18T17:33:30Z")

</div>

Sir one thing more the code you have given is worked for debit side only. But as you see there are credit table also and I have to check credit box which have different SL NO.  
in this case what should I do

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 18, 2022, 5:37pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/33 "2022-07-18T17:37:22Z")

</div>

Here SL No will be two. One for for debit and another for credit. what should i do sir?

‘’'driver = DriverFactory.getWebDriver()

def requestedRef = “your SL No here”

WebElement table = driver.findElement(By.xpath(‘id(“grdDebitTrn”)/tbody’));

List rowsOfTable = table.findElements(By.tagName(‘tr’));

boolean found = false;  
int rowCnt = rowsOfTable.size();

for (int cnt = 0; cnt \< rowCnt; cnt++) {  
List columnCells = rowsOfTable.get(cnt).findElements(By.tagName(‘td’));

```
cellText = columnCells.get(1).findElement(By.tagName('span')).getText();

if (cellText == requestRef) {
    found = true;
    columnCells.get(0).findElement(By.tagName('span')).click();
    break;
}

```

}

if (!found) {

```
table = driver.findElement(By.xpath('id("grdCreditTrn")/tbody'));

rowsOfTable = table.findElements(By.tagName('tr'));

rowCnt = rowsOfTable.size();

for (int cnt = 0; cnt < rowCnt; cnt++) {
    columnCells = rowsOfTable.get(cnt).findElements(By.tagName('td'));

    cellText = columnCells.get(1).findElement(By.tagName('span')).getText();

    if (cellText == requestRef) {

        columnCells.get(0).findElement(By.tagName('span')).click();
        break;
    }
}'''

```

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 5:46pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/34 "2022-07-18T17:46:54Z")

</div>

If you have a debit reference number and credit reference number then you will have to search for each number within its respective “area”. Again, take some time and see what you can pick up. Obviously, you should try **not** to have the debit reference number run through the credit "area’ and vice versa for the credit reference number running through the debit “area” if they don’t need to.

> **Maybe like:**
>
> ```auto
> driver = DriverFactory.getWebDriver()
> 
> def debitRequestedRef = "debit SL No here"
> def creditRequestedRef = "credit SL No here"
> 
> WebElement table = driver.findElement(By.xpath('id("grdDebitTrn")/tbody'));
> 
> List<WebElement> rowsOfTable = table.findElements(By.tagName('tr'));
> 
> int rowCnt = rowsOfTable.size();
> 
> if (debitRequestedRef != "") {
> Loop:
> for (int cnt = 1; cnt < rowCnt; cnt++) {
> List<WebElement> columnCells = rowsOfTable.get(cnt).findElements(By.tagName('td'));
> 		
> cellText = columnCells.get(1).findElement(By.tagName('span')).getText();
> 		
> if (cellText == debitRequestedRef ) {
> columnCells.get(0).findElement(By.tagName('span')).click();
> break Loop;
> }
> }
> }
> 
> table = driver.findElement(By.xpath('id("grdCreditTrn")/tbody'));
> 
> rowsOfTable = table.findElements(By.tagName('tr'));
> 
> rowCnt = rowsOfTable.size();
> 
> if (creditRequestedRef != "") {
> Loop:
> for (int cnt = 1; cnt < rowCnt; cnt++) {
> columnCells = rowsOfTable.get(cnt).findElements(By.tagName('td'));
> 		
> cellText = columnCells.get(1).findElement(By.tagName('span')).getText();
> 		
> if (cellText == creditRequestedRef) {
> 		
> columnCells.get(0).findElement(By.tagName('span')).click();
> break Loop;
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 18, 2022, 6:09pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/35 "2022-07-18T18:09:47Z")

</div>

![image](https://europe1.discourse-cdn.com/katalon/original/3X/1/a/1aba12d732097fddd98fca7eda0001bc93b4edda.png)

Sir for this code i am facing problem. I tried Ctrl+Shift+O. But same result.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 7:10pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/36 "2022-07-18T19:10:35Z")

</div>

I did it again. Start loops from 1, not zero.

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 18, 2022, 7:33pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/37 "2022-07-18T19:33:37Z")

</div>

Sir changing loops to 1 from 0. it is clicking on debit checkbox only. but credit checkbox requested value is not checked.

‘’'import org.openqa.selenium.By  
import org.openqa.selenium.WebElement

import com.kms.katalon.core.webui.driver.DriverFactory  
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser(‘’)

WebUI.maximizeWindow()

WebUI.navigateToUrl(‘file:///C:/Users/hp/Desktop/GS.html’)

WebUI.waitForPageLoad(10)  
driver = DriverFactory.getWebDriver()

def debitRequestedRef = “3193263”  
def creditRequestedRef = “3704854”

WebElement table = driver.findElement(By.xpath(‘id(“grdDebitTrn”)/tbody’));

List rowsOfTable = table.findElements(By.tagName(‘tr’));

int rowCnt = rowsOfTable.size();

if (debitRequestedRef != “”) {  
for (int cnt = 1; cnt \< rowCnt; cnt++) {  
List columnCells = rowsOfTable.get(cnt).findElements(By.tagName(‘td’));

```
    cellText = columnCells.get(1).findElement(By.tagName('span')).getText();

    if (cellText == debitRequestedRef ) {
        columnCells.get(0).findElement(By.tagName('span')).click();
        break;
    }
}

```

}

table = driver.findElement(By.xpath(‘id(“grdCreditTrn”)/tbody’));

rowsOfTable = table.findElements(By.tagName(‘tr’));

rowCnt = rowsOfTable.size();

if (creditRequestedRef != “”) {  
for (int cnt = 0; cnt \< rowCnt; cnt++) {  
columnCells = rowsOfTable.get(cnt).findElements(By.tagName(‘td’));

```
    cellText = columnCells.get(1).findElement(By.tagName('span')).getText();

    if (cellText == creditRequestedRef) {

        columnCells.get(0).findElement(By.tagName('span')).click();
        break;
    }
}

```

}‘’’

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/3/6/36e443855f78c0136f587f51bc4ca2c89af90405.png)

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 18, 2022, 8:35pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/38 "2022-07-18T20:35:03Z")

</div>

> [@sanjoy2016ewu](#):
>
> for (int cnt = 0; cnt \< rowCnt; cnt++) {

Change the second counter to 1 also.

Put the 3 back ticks on a **line by itself above** the code and another set of 3 back ticks on a **line by itself below** the code.

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 19, 2022, 2:50am UTC](https://forum.katalon.com/t/table-dynamic-search/66577/39 "2022-07-19T02:50:08Z")

</div>

Sir it’s working for both sides properly. Thanks a lot sir.  
But when I am give the last debit serial number katalon is taking a lot of time to select that one. Which is a problem.

And still I am unable to find out the way of using excel use. I am trying. Hope will be able by using your given links.  
Love you sir’.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 19, 2022, 5:23am UTC](https://forum.katalon.com/t/table-dynamic-search/66577/40 "2022-07-19T05:23:00Z")

</div>

Take a look at my previous post as I made a small change to the code to hopefully speed up the search.

> [@Table dynamic Search](http://forum.katalon.com/t/table-dynamic-search/66577/34):
>
> If you have a debit reference number and credit reference number then you will have to search for each number within its respective “area”. Again, take some time and see what you can pick up. Obviously, you should try not to have the debit reference number run through the credit "area’ and vice versa for the credit reference number running through the debit “area” if they don’t need to. 
> 
> > **Maybe like:**
> >
> > driver = DriverFactory.getWebDriver() def debitRequestedRef = "debit SL No here" def …

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 19, 2022, 4:26pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/41 "2022-07-19T16:26:49Z")

</div>

Sir I am using this code for excel file data. But not working.  
Where is the problem.  
And where this code should be use in script?  
[JJJ.xlsx](https://forum.katalon.com/uploads/short-url/xkLCJasc48seteONsLFkQLnv0zk.xlsx) (8.3 KB)

‘’'Object excelFile = ExcelFactory.getExcelDataWithDefaultSheet(“your\_excelFile\_location.xlsx”, “JJJ”, true)

for (int index = 1; index \< excelFile.size(); index++)  
{  
println excelFile.getValue(“debitRequestedRef”, index) + " " + excelFile.getValue(“creditRequestedRef”, index)  
}‘’’

---

<div class="post-metadata">

**Author:** ![sanjoy2016ewu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sanjoy2016ewu/32/22419_2.png) [@sanjoy2016ewu](https://forum.katalon.com/u/sanjoy2016ewu)\
**Post date:** [July 19, 2022, 6:53pm UTC](https://forum.katalon.com/t/table-dynamic-search/66577/42 "2022-07-19T18:53:14Z")

</div>

Sir please help. I am unable to search data from excel file. I tired a lot. Please help sir.

[Previous page](https://forum.katalon.com/t/table-dynamic-search/66577.md?page=1)

[Next page](https://forum.katalon.com/t/table-dynamic-search/66577.md?page=3)
