# Click on specific item in list/table

**URL:** <https://forum.katalon.com/t/click-on-specific-item-in-list-table/34644>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [October 14, 2019, 7:20pm UTC](https://forum.katalon.com/t/click-on-specific-item-in-list-table/34644 "2019-10-14T19:20:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlilly](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mlilly](https://forum.katalon.com/u/mlilly)\
**Post date:** [October 14, 2019, 7:20pm UTC](https://forum.katalon.com/t/click-on-specific-item-in-list-table/34644/1 "2019-10-14T19:20:17Z")

</div>

I am very new to Katalon and would like for the test case to click on a specific item in a list/table on the current page based on the text the table cell contains.

---

<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:** [October 14, 2019, 7:24pm UTC](https://forum.katalon.com/t/click-on-specific-item-in-list-table/34644/2 "2019-10-14T19:24:05Z")

</div>

> [@mlilly](#):
>
> I am very new to Katalon and would like for the test case to click on a specific item in a list/table on the current page based on the text the table cell contains.

Katalon can do that but what we need from you is lot more information. Read this post to get some ideas:

> [@\[TIP\] How To Help Us Help You!](http://forum.katalon.com/t/tip-how-to-help-us-help-you-my-test-is-broken-nothing-works-please-help-me/12919):
>
> My test is BROKEN! NOTHING WORKS! HELP ME! Relax. We get it. We really do. There are some pretty smart and clever people on this forum, but you must realize, they are not magicians or wizards or gods. They cannot see your code, they can’t see your errors and they don’t even know what your AUT is meant to do even though it might seem perfectly obvious to you. So please relax and follow the advice below, before you start writing your post. The advice below will tell you the exact information …

> [@](#):
>
> Also when there are duplicates in the table, is there a way to click on the item with the most recent timestamp?

Please limit your topic to one question. Post this as a new topic. Thanks!

---

<div class="post-metadata">

**Author:** ![mlilly](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mlilly](https://forum.katalon.com/u/mlilly)\
**Post date:** [October 14, 2019, 8:19pm UTC](https://forum.katalon.com/t/click-on-specific-item-in-list-table/34644/3 "2019-10-14T20:19:37Z")

</div>

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

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

I found the following when googling but have no idea if this is what I need:

import org.openqa.selenium.By as By  
import org.openqa.selenium.WebDriver as WebDriver  
import org.openqa.selenium.WebElement as WebElement  
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory  
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.maximizeWindow()  
‘Expected value from Table’  
String ExpectedValue = ‘545164320’  
WebDriver driver = DriverFactory.getWebDriver()  
‘To locate table’  
WebElement Table = driver.findElement(By.xpath(‘//table/tbody’))  
'To locate rows of table it will Capture all the rows available in the table ’  
List \< WebElement \> Rows = Table.findElements(By.tagName(‘tr’))  
println('No. of rows: ’ + Rows.size())  
‘Find a matching text in a table and performing action’  
‘Loop will execute for all the rows of the table’  
table: for (int i = 0; i \< Rows.size(); i++) {  
‘To locate columns(cells) of that specific row’  
List \< WebElement \> Cols = Rows.get(i).findElements(By.tagName(‘td’))  
for (int j = 0; j \< Cols.size(); j++) {  
‘Verifying the expected text in the each cell’  
if (Cols.get(j).getText().equalsIgnoreCase(ExpectedValue)) {  
‘To locate anchor in the expected value matched row to perform action’  
Cols.get(4).findElement(By.tagName(‘a’)).click()  
table: break  
}  
}  
}

These are my errors. It is failing at  
2019-10-14 15:40:45.527 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 60: driver = getWebDriver()  
2019-10-14 15:40:45.529 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 61: Table = driver.findElement(By.xpath(“//table/tbody”))  
2019-10-14 15:40:45.555 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 62: Rows = Table.findElements(By.tagName(“tr”))  
2019-10-14 15:40:45.630 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 63: println("No. of rows: " + Rows.size())  
No. of rows: 10  
2019-10-14 15:40:45.645 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 64: “Find a matching text in a table and performing action”  
2019-10-14 15:40:45.645 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 65: for ([i = 0, i \< Rows.size(), (i++)])  
2019-10-14 15:40:45.646 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 1: Cols = get(i).findElements(By.tagName(“td”))  
2019-10-14 15:40:45.661 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 2: for ([j = 0, j \< Cols.size(), (j++)])  
2019-10-14 15:40:45.662 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 1: if (getText().equalsIgnoreCase(ExpectedValue))  
2019-10-14 15:40:45.676 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 1: if (getText().equalsIgnoreCase(ExpectedValue))  
2019-10-14 15:40:45.688 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 1: if (getText().equalsIgnoreCase(ExpectedValue))  
2019-10-14 15:40:45.704 DEBUG testcase.DE2001 - Add DE2 Outbound Bill - 1: tagName(“a”)).click()  
2019-10-14 15:40:45.737 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/DE2/DE2001 - Add DE2 Outbound Bill FAILED.  
Reason:  
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“a”}  
(Session info: chrome=76.0.3809.132)  
For documentation on this error, please visit: [https://www.seleniumhq.org/exceptions/no\_such\_element.html](https://www.seleniumhq.org/exceptions/no_such_element.html)  
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’  
System info: host: ‘HKYNCTIINF20L’, ip: ‘10.2.24.81’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0\_181’  
Driver info: com.kms.katalon.selenium.driver.CChromeDriver  
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 76.0.3809.132, chrome: {chromedriverVersion: 76.0.3809.68 (420c9498db8ce…, userDataDir: C:\Users\MLilly\AppData\Loc…}, goog:chromeOptions: {debuggerAddress: localhost:64496}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}  
Session ID: bc8bf6f9346b5e6ad3eb10bc88b3e99c  
\*\*\* Element info: {Using=tag name, value=a}  
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)  
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)  
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)  
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)  
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)  
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)  
at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:20)  
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)  
at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:185)  
at org.openqa.selenium.remote.RemoteWebElement.findElementByTagName(RemoteWebElement.java:277)  
at org.openqa.selenium.By$ByTagName.findElement(By.java:320)  
at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:181)  
at org.openqa.selenium.WebElement$findElement$1.call(Unknown Source)  
at DE2001 - Add DE2 Outbound Bill.run(DE2001 - Add DE2 Outbound Bill:157)  
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)  
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)  
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)  
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)  
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)  
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)  
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)  
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)  
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)  
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)  
at TempTestCase1571081960300.run(TempTestCase1571081960300.groovy:21)

---

<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:** [October 14, 2019, 8:51pm UTC](https://forum.katalon.com/t/click-on-specific-item-in-list-table/34644/4 "2019-10-14T20:51:40Z")

</div>

No, it doesn’t seem to be the code you need, but let’s see if we can move it in the right direction.

It looks as though the test gets to this line:

```auto
if (Cols.get(j).getText().equalsIgnoreCase(ExpectedValue)) {

```

then fails on this line:

```auto
Cols.get(4).findElement(By.tagName(‘a’)).click()

```

> [@mlilly](#):
>
> Reason:  
> org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“a”}

There are two things I think might be wrong.

1. The error is correct. You are trying to access an a-element which does not exist. You have a td-element which contains the expected text, not an a-element.

2. The code you found seems to want to match on the first cell it finds containing the expected text but THEN tries to click on the a-element in cell(4). Since you highlighted a cell in the _third_ column, I’m guessing you want a different cell with an a-element - but I can’t say which one because I can’t see it from your screenshot.

Regarding this:

> [@mlilly](#):
>
> I found the following when googling but have no idea if this is what I need:

Please understand, I can’t teach you testing or programming. All I can do is give you pointers toward things you can use and develop yourself.

Also, please understand we are working blind here. You have all the resources and our help is as limited as the help you provide us to understand your problem. If your problem is your lack of knowledge about Katalon/Testing/Programming, you should put in the time to study.

Start here:

[https://docs.katalon.com/katalon-studio/videos/index.html](https://docs.katalon.com/katalon-studio/videos/index.html)
