# Retrieval of corresponding values

**URL:** <https://forum.katalon.com/t/retrieval-of-corresponding-values/29424>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [July 10, 2019, 10:10am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424 "2019-07-10T10:10:21Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![vdavuluri2](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vdavuluri2](https://forum.katalon.com/u/vdavuluri2)\
**Post date:** [July 10, 2019, 10:10am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/1 "2019-07-10T10:10:21Z")

</div>

Hi,  
I wanted to retrieve the date 05/05/17 value by searching with the value 214 value as per the attachment. That means it should search in the page and identify the value and get the corresponding value of that. How I can do with the Groovy ? How to do with xpath ?  
Please suggest to proceed further.

Please find the attached file for html code and screen shot of the web page.

[html code1.txt](https://europe1.discourse-cdn.com/katalon/original/2X/9/9b064ff38fc2ab494fc5e48f852a79e7e46792d1.txt) (1.0 MB)

 ![snap](https://europe1.discourse-cdn.com/katalon/original/2X/d/dd9e29b259a0de2475e4ca990d87cce4c48129f0.png)

---

<div class="post-metadata">

**Author:** ![Arnel](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arnel/32/6360_2.png) [@Arnel](https://forum.katalon.com/u/Arnel)\
**Post date:** [July 10, 2019, 11:08am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/2 "2019-07-10T11:08:29Z")

</div>

Hi vdavuluri,

Dealing with a list is not quite simple, you need to observe and be aware of the common locators of the items or row. It will be a lot of explanations.

To make it short, I suggest getting the xpath of the whole row or the attribute/locators that are common to them. Use them as your test object.

To give you an idea, refer to this code. . .

```auto
//import WebElement
import org.openqa.selenium.WebElement

//create a list
//this line will be the storing location of your items once it becomes visible to your website.
java.util.List<WebElement> _rowCommonLocator = WebUiCommonHelper.findWebElements(findTestObject("Common_Locator_of_the_rows"), 30)

//use a loop to go through all the row items
for(int rowIndex = 0; rowIndex < _rowCommonLocator.size(); rowIndex++)
{
    /**this if condition here will decide if the row contains "214" and "05/05/17"
        if not then it will continue to loop.
    **/
	if(_rowCommonLocator[rowIndex].text.contains("214")) &&
	   _rowCommonLocator[rowIndex].text.contains("05/05/17")
	  {
         if(_rowCommonLocator[rowIndex].text.contains("REVIEW"))
         {
                //since the characters of the rows are consistent, play with substring and eliminate unnecesary text to get your desired text output
                println _rowCommonLocator[rowIndex].text.substring(int beginIndex, int endIndex)
                break
         }
         else
         {
               //another substring value if the row doesnt contain "REVIEW" or "OPEN"
               break
         }	
      }
}

```

Hope that helps. . . 🙂

---

<div class="post-metadata">

**Author:** ![vdavuluri2](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vdavuluri2](https://forum.katalon.com/u/vdavuluri2)\
**Post date:** [July 10, 2019, 12:50pm UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/3 "2019-07-10T12:50:20Z")

</div>

Arnel,  
Thank you so much for your clarifications.  
What should be given after the findTestObject ? what needs to be captured here or do we need mention about the xpath details here ?

java.util.List\<WebElement\> \_rowCommonLocator = WebUiCommonHelper.findWebElements(findTestObject(“Common\_Locator\_of\_the\_rows”), 30)

**Please clarify.**

---

<div class="post-metadata">

**Author:** ![Arnel](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arnel/32/6360_2.png) [@Arnel](https://forum.katalon.com/u/Arnel)\
**Post date:** [July 11, 2019, 2:09am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/4 "2019-07-11T02:09:25Z")

</div>

Hi vdavuluri,

Sorry I didn’t explained it much on my last reply. . .

Regarding this. . . . .

> [@vdavuluri2](#):
>
> What should be given after the findTestObject ? what needs to be captured here or do we need mention about the xpath details here ?

What I mean is **inspect the whole row and get the xpath** (Make the browser inspector highlight the whole row then get the xpath, **right click and copy xpath** ) or **find common attribute like class, name, title,** etc. . . .

Then **create a test object using the captured xpath or attribute** then that will be your findTestObject(“Common\_Locator\_of\_the\_rows”). After successfully performing that step, print the \_rowCommonLocator as said in my last reply. You will get an array output of:

```auto
[110OPEN05/07/2013GS00T07NSD0007IIT05/08/2013 04:00:00 PM, 204OPEN02/02/2017GS00T07NSD0007SFS02/02/2017/ 04:00:00 PM, and so on. . . . . . . .]

```

That means you have successfully captured all rows in the list, then after that refer to the code I provided. . .

Hope that makes sense. . . 🙂

---

<div class="post-metadata">

**Author:** ![vdavuluri2](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vdavuluri2](https://forum.katalon.com/u/vdavuluri2)\
**Post date:** [July 11, 2019, 7:16am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/5 "2019-07-11T07:16:24Z")

</div>

Appreciate your quick help, Arnel.  
Please find the attachments and mentioned about the question in each snap. Can you please look into this and suggest to proceed further ?

THANK YOU.

 ![Snap1](https://europe1.discourse-cdn.com/katalon/original/2X/3/320d4786fa29c3e05b4aef04ce6ae46648d3816b.png) ![Snap2](https://europe1.discourse-cdn.com/katalon/original/2X/7/7111e6af79109c72f63e76c2b499564a2e93407f.png)

---

<div class="post-metadata">

**Author:** ![Arnel](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arnel/32/6360_2.png) [@Arnel](https://forum.katalon.com/u/Arnel)\
**Post date:** [July 11, 2019, 7:58am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/6 "2019-07-11T07:58:47Z")

</div>

Hi vdavuluri,

As I mention. . . . .

> [@Arnel](#):
>
> **find common attribute like class, name, title,** etc. . . .

See that “bgRow1”, “bgRow2” ??? They are common right??? Then use that as your locator.. Create a new test object using that class attribute, but remove the number at the last part for them to become common and in order for the code to look for those items and be stored in your array list.

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

Then. . . . .

> [@Arnel](#):
>
> after that refer to the code I provided. . .

```auto
java.util.List<WebElement> lists = WebUiCommonHelper.findWebElements(findTestObject("Object Repository/Rows"), 30)

```

It will be very hard for you if you do not play with it. As I said it’s not easy dealing with lists. . .  
Expand this idea. Not all list contains the same information or attribute inside. . .

Hope that helps. . . .

---

<div class="post-metadata">

**Author:** ![vdavuluri2](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vdavuluri2](https://forum.katalon.com/u/vdavuluri2)\
**Post date:** [July 11, 2019, 1:28pm UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/7 "2019-07-11T13:28:51Z")

</div>

Thank you, Arnel.  
I am testing to see what data will be stored in the element and I encountered the below error for below step definition. Can you please just give idea how to I keep it in xpath and it does not need the exact answers. Small guidance to proceed further. THANKS FOR YOUR HELP.

**Step Definition:**  
@And(“user should verify that assigned tracking number displayed with resultsass”)  
def should\_verify\_assigned\_tracking\_number\_disp\_results() {  
if(runIndicator4!=‘N’) {  
WebElement element = WebUiCommonHelper.findWebElement(By.xpath(“//a[starts-  
with(@tr=‘bgRow’)]”,30))  
println("Number of elements: " + element.size());  
WebUI.delay(10)  
}  
}

**Error from Log:**

> 2019-07-11 18:50:15.744 ERROR c.k.k.c.c.keyword.CucumberReporter - ❌ user should verify that assigned tracking number displayed with resultsass FAILED.  
> Reason:  
> groovy.lang.MissingMethodException: No signature of method: static org.openqa.selenium.By.xpath() is applicable for argument types:  
> (java.lang.String, java.lang.Integer) values: [//a[starts-with(@tr=‘bgRow’)], 30]  
> Possible solutions: xpath(java.lang.String), wait(), any(), wait(long, int), name(java.lang.String), getAt(java.lang.String)  
> at AssignInquiry004.should\_verify\_assigned\_tracking\_number\_disp\_results(AssignInquiry004.groovy:198)  
> at ✽.user should verify that assigned tracking number displayed with resultsass(C:/Users/vdavuluri2/Katalon Studio/Govt Inquiry/Include/features/Assign Inquiry-004.feature:26)

---

<div class="post-metadata">

**Author:** ![Arnel](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arnel/32/6360_2.png) [@Arnel](https://forum.katalon.com/u/Arnel)\
**Post date:** [July 12, 2019, 3:23am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/8 "2019-07-12T03:23:17Z")

</div>

Hi vdavuluri,

Maybe this tip will help you. Take time to read. . .

> [@Working on Lists or Dropdown](http://forum.katalon.com/t/working-on-lists-or-dropdown/29499):
>
> Hi there Guys, LONG POST AHEAD! Take time to read. . . wink Ok so, I’ll be posting this since I notice this last few weeks, some or many of the posted issues here in the forum are regarding or they are dealing with lists or dropdown. So I’ll be sharing you some idea that might help you because when dealing with lists or dropdown I always use this approach and it is very effective. Its not quite easy working on lists or dropdown, it requires a lot of observations and tries but when you get …

Hope that helps you. . . 🙂

---

<div class="post-metadata">

**Author:** ![vdavuluri2](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vdavuluri2](https://forum.katalon.com/u/vdavuluri2)\
**Post date:** [July 12, 2019, 10:14am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/9 "2019-07-12T10:14:48Z")

</div>

Yes… It is really helped, Arnel. Thank You so much.  
Below is my code and it is working fine almost. The question is now, I will have to check for the class **“bgRow2”**. So how do I check both the classes in single line or regular expression. Only this clarification is pending. THANKS

**CODE**  
@When(“user click on Bulk Assignment linkass”)  
def user\_click\_on\_bulk\_assignment\_link() {  
WebDriver driver2 = DriverFactory.getWebDriver()  
WebElement Table2 = driver2.findElement(By.xpath("//table[@id=‘mTAB1’]/tbody"))  
List rows\_table2 = Table2.findElements(By.className(“bgRow1”))  
int rows\_count2 = rows\_table2.size()

```
	   for(int j=0; j < rows_count2; j++)
		 {
		   List<WebElement> cols2 = rows_table2.get(j).findElements(By.tagName('td'))
		   int cols_count2 = cols2.size()
		   println " cols_count2 in each row2 " + cols_count2
		   println " rows_table2.get(j) " + rows_table2.get(j)
		   for (int colum2 = 0; colum2 < cols_count2; colum2++)
			   {
                                                                       if(colum2==6)
			      {
			       valstore[intal] = cols2.get(colum2).getText()
				   String celltext2 = cols2.get(colum2).getText()
			       println "celltext2 " + celltext2
				   intal = intal + 1
                                                                               }
				if(j==4) j=1000;  
			   }
		 }
	   
	   / **CLICK ON BULK ASSIGN** /
	   WebUI.click(findTestObject('Object Repository/ORTC04/Page_Govt Inquiry/a_Bulk Assign'), FailureHandling.STOP_ON_FAILURE)
	   WebUI.delay(5)
	}
}

```

**And also…**  
I see the below error when I execute the below mentioned step definition…

**Step Definition**  
@When(“user click on Bulk Assignment linkass”)  
def user\_click\_on\_bulk\_assignment\_link() {  
WebDriver driver2 = DriverFactory.getWebDriver()  
WebElement Table2 = driver2.findElement(By.xpath("//table[@id=‘mTAB1’]/tbody"))  
List rows\_table2 = Table2.findElements(By.className(“bgRow1”))  
int rows\_count2 = rows\_table2.size()

```
	   for(int j=0; j < rows_count2; j++)
		 {
		   List<WebElement> cols2 = rows_table2.get(j).findElements(By.tagName('td'))
		   int cols_count2 = cols2.size()
		   println " cols_count2 in each row2 " + cols_count2
		   println " rows_table2.get(j) " + rows_table2.get(j)
		   for (int colum2 = 0; colum2 < cols_count2; colum2++)
			   {
                                                                       if(colum2==6)
			      {
			       valstore[intal] = cols2.get(colum2).getText()
				   String celltext2 = cols2.get(colum2).getText()
			       println "celltext2 " + celltext2
				   intal = intal + 1
                                                                               }
				if(j==4) j=1000;  
			   }
		 }
	   
	   / **CLICK ON BULK ASSIGN** /
	   WebUI.click(findTestObject('Object Repository/ORTC04/Page_Govt Inquiry/a_Bulk Assign'), FailureHandling.STOP_ON_FAILURE)
	   WebUI.delay(5)
	}
}

```

**Error Log**  
rows\_count2 10  
cols\_count2 in each row2 44  
rows\_table2.get(j) [[[[CChromeDriver: chrome on XP (c9105cad763f08278655b121b95ef3f9)] -\> xpath: //table[@id=‘mTAB1’]/tbody]] -\> class name: bgRow1]  
2019-07-12 20:53:12.083 ERROR c.k.k.c.c.keyword.CucumberReporter - ❌ user click on Bulk Assignment linkass FAILED.  
Reason:  
java.lang.IllegalArgumentException: String of length 1 expected but got a bigger one  
at AssignInquiry004.user\_click\_on\_bulk\_assignment\_link(AssignInquiry004.groovy:270)  
at ✽.user click on Bulk Assignment linkass(C:/Users/vdavuluri2/Katalon Studio/Govt Inquiry/Include/features/Assign Inquiry-004.feature:28)

---

<div class="post-metadata">

**Author:** ![Arnel](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arnel/32/6360_2.png) [@Arnel](https://forum.katalon.com/u/Arnel)\
**Post date:** [July 13, 2019, 12:01pm UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/10 "2019-07-13T12:01:52Z")

</div>

Hi vdavuluri,

What do you mean by this?

> [@vdavuluri2](#):
>
> So how do I check both the classes in single line or regular expression

Is it do you want to check the value of the class??

If so, then use getAttribute method of WebElement. . .

```auto
String attributeValue = yourList[index].getAttribute("class")

```

Also if you want to include **“bgRow2”** in your list, remove the number from the last part. It should only be **“bgRow”** inorder for your list to capture all the items in your list. . .

> [@vdavuluri2](#):
>
> List rows\_table2 = Table2.findElements(By.className(“bgRow1”))  
> int rows\_count2 = rows\_table2.size()

As you can see in your previous reply, the first screenshot you have sent, all of them are “bgRow1” and yet you still use “bgRow1”. So it will just get all the “bgRow1” and “bgRow2” will be left behind. That’s why you need to remove the number from the last part to make all items the same so that your list can capture them all.

It should be like this:

```auto
List rows_table2 = Table2.findElements(By.className(“bgRow”))

```

🙂

---

<div class="post-metadata">

**Author:** ![vdavuluri2](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vdavuluri2](https://forum.katalon.com/u/vdavuluri2)\
**Post date:** [July 15, 2019, 6:51am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/11 "2019-07-15T06:51:51Z")

</div>

Thanks for the detailed steps, Arnel.  
**Question : 1**  
Yes.. As I showed in earlier, it has one row with “bgRow1” and another row with “bgRow2”. So, to capture both the classes, asked about the how to track the last digit. When I tried with  
**List rows\_table2 = Table2.findElements(By.className(“bgRow”))**, it is not not identifying any classname. Do I need to keep any “?” or other to track in the last digit ?

**Question : 2**  
With getAttribute, will I get the classname ? what should be given for yourList(index) ?  
String attributeValue = yourList[index].getAttribute(“class”)

**Question : 3**  
When I try to execute the below step definition, getting the attached error at the below highlighted code with array - **valstore[intal] = cols2.get(colum2).getText()**. I have verified at the debugging mode. It is looking for **io.cucumber.core\_3.0.2.jar** file.

**Step Definition**  
@When(“user click on Bulk Assignment linkass”)  
def user\_click\_on\_bulk\_assignment\_link() {  
WebDriver driver2 = DriverFactory.getWebDriver()  
WebElement Table2 = driver2.findElement(By.xpath(“//table[@id=‘mTAB1’]/tbody”))  
List rows\_table2 = Table2.findElements(By.className(“bgRow1”))  
int rows\_count2 = rows\_table2.size()

for(int j=0; j \< rows\_count2; j++)  
{  
List cols2 = rows\_table2.get(j).findElements(By.tagName(‘td’))  
int cols\_count2 = cols2.size()  
println " cols\_count2 in each row2 " + cols\_count2  
println " rows\_table2.get(j) " + rows\_table2.get(j)  
for (int colum2 = 0; colum2 \< cols\_count2; colum2++)  
{  
if(colum2==6)  
{  
**valstore[intal] = cols2.get(colum2).getText()**  
String celltext2 = cols2.get(colum2).getText()  
println "celltext2 " + celltext2  
intal = intal + 1  
}  
if(j==4) j=1000;  
}  
}

```
   / **CLICK ON BULK ASSIGN** /
   WebUI.click(findTestObject('Object Repository/ORTC04/Page_Govt Inquiry/a_Bulk Assign'), FailureHandling.STOP_ON_FAILURE)
   WebUI.delay(5)
}

```

}

 ![io_cucumber_core](https://europe1.discourse-cdn.com/katalon/original/2X/d/daf1de90aa2aa27346901951d18cfe6e35b0ae3c.png)

---

<div class="post-metadata">

**Author:** ![Arnel](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arnel/32/6360_2.png) [@Arnel](https://forum.katalon.com/u/Arnel)\
**Post date:** [July 15, 2019, 10:28am UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/12 "2019-07-15T10:28:38Z")

</div>

Hi. . .

For question 1:  
Sorry I was wrong about this:

```auto
List rows_table2 = Table2.findElements(By.className(“bgRow”))

```

It should be contains:

```auto
List rows_table2 = Table2.findElements(By.xpath(“//*[contains(@class, 'bgRow')]”))

```

For question 2:

- You will get the value of the classname. e.g. yourList[index].getAttribute(“class”), it will return the classname of the specified index.  
Sample Code:

```auto
WebDriver driver2 = DriverFactory.getWebDriver()
WebElement Table2 = driver2.findElement(By.xpath("//table[@id=‘mTAB1’]/tbody"))
List rows_table2 = Table2.findElements(By.Xpath("//*[contains(@class, 'bgRow')]”))
int rows_count2 = rows_table2.size()

String attributeValue = rows_table2[SampleIndex].getAttribute("class")

```

For question 3:

- I don’t have any idea for that, sorry.

Hope that answer your questions. . . .

---

<div class="post-metadata">

**Author:** ![vdavuluri2](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vdavuluri2](https://forum.katalon.com/u/vdavuluri2)\
**Post date:** [July 15, 2019, 12:29pm UTC](https://forum.katalon.com/t/retrieval-of-corresponding-values/29424/13 "2019-07-15T12:29:29Z")

</div>

Thank You so much, **Arnel**. Thanks for your inputs.
