Table dynamic Search

Is any need to count the row s? I just need to search the serial number and want to check that checkbox

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:

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

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

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 .

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.

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:

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

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).

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.

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 ?

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.

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

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;
    }
}'''

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 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;
		}
	}
}

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

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

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;
    }
}

}‘’’

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.

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’.

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

1 Like

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 (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)
}‘’’