# The "xpath" for the url is correct but not visible if added via addProperty

**URL:** <https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662>\
**Category:** Miscellaneous\
**Created:** [June 22, 2018, 2:50am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662 "2018-06-22T02:50:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 22, 2018, 2:50am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/1 "2018-06-22T02:50:30Z")

</div>

Hello

I created this topic as it was suggested to open a new one.

Here is the scenario - and posting becuase did not find the specific case like this.

**CASE 1:**

- Added a TO “LinkTest” into Object Repository and only 1 attribute: xpath

//a[@href=‘[Problem Encountered](http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604)’]

WebUI.click(findTestObject(‘Page\_Inbox/LinkTest’))

**RESULT:** Works without issue.

**CASE 2:**

- Added a TO on the fly without adding it to Object Repository

- The “xpath” is stored in the .csv and it is the same as in case # 1

CSVData data = findTestData(“DDT1”)

for (def index : (0…data.getRowNumbers() - 1)) {

def EmailPath = new TestObject(“Link in the email”)

def exprURL = data.internallyGetValue(“xPath”, index)

println(exprURL)

EmailPath.addProperty(“xpath”, ConditionType.EQUALS, exprURL)

WebUI.verifyElementPresent(EmailPath, 10, FailureHandling.STOP\_ON\_FAILURE)

WebUI.click(EmailPath)}

**RESULT:** Errors with this message:

\_Unable to verify object ‘Link in the email’ is present \_

\_(Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: \_

\_Web element with id: ‘Link in the email’ located by \_

_'By.xpath: //a[@href='[Problem Encountered](http://clickplus103.com/clk.trk?CID=410486&AFID=423399&dwi_e=8a4030fb-3dec-4cf2-8de8-ed059b79b454'%5D') not found)_

Thank you

Andrew

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [June 22, 2018, 3:18am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/2 "2018-06-22T03:18:27Z")

</div>

Hello Andrew,  
just to be sure: you are trying to find same DOM object in both cases (no change on page). Because x-paths you send as examples are not same at all.  
Sorry i just want to be sure that i get it correctly.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 22, 2018, 4:21am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/3 "2018-06-22T04:21:03Z")

</div>

Andrew,

I think you need to make sure your xpath is valid. You do not need Katalon Studio to verify your xpath. You should get used to alternative xpath tool. Google Chrome and Firefox has built-in function. See

- [https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference](https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference)

Try the following steps:

1. Open Chrome and navigate to your target URL  
2. Press F12 to open up Chrome DevTools  
3. Switch to Console pane  
4. Type

```auto
$x("//a[@href='http://clickplus103.com/clk.trk?CID=410486&AFID=423399&dwi_e=8a4030fb-3dec-4cf2-8de8-ed059b79b454']")

```

5. Check if the xpath expression selects what you intended or not.

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 22, 2018, 10:04am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/4 "2018-06-22T10:04:52Z")

</div>

> Andrej Podhajský said:
> 
> Hello Andrew,  
> just to be sure: you are trying to find same DOM object in both cases (no change on page). Because x-paths you send as examples are not same at all.  
> Sorry i just want to be sure that i get it correctly.

Hi Andrej

This is correct - i use the same xpath in both cases. If interested i can add screen shots. But here it is in both situations:  
**//a[**[**@href='**](http://forum.katalon.com/profile//href%3D%27)[**http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604’]**](http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604%27%5D)

Please let me know if you see the some difference.

Thank you,  
Andrew

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 22, 2018, 10:15am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/5 "2018-06-22T10:15:07Z")

</div>

> kazurayam said:
> 
> Andrew,
> 
> I think you need to make sure your xpath is valid. You do not need Katalon Studio to verify your xpath. You should get used to alternative xpath tool. Google Chrome and Firefox has built-in function. See
> 
> - [Chrome DevTools - Chrome for Developers](https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference)
> 
> Try the following steps:
> 
> 1. Open Chrome and navigate to your target URL  
> 2. Press F12 to open up Chrome DevTools  
> 3. Switch to Console pane  
> 4. Type
> 
> ```auto
> $x("//a[@href='http://clickplus103.com/clk.trk?CID=410486&AFID=423399&dwi_e=8a4030fb-3dec-4cf2-8de8-ed059b79b454']")
> 
> ```
> 
> 5. Check if the xpath expression selects what you intended or not.

Good Day [kazurayam](http://forum.katalon.com/profile/4280/kazurayam "Link: http://forum.katalon.com/profile/4280/kazurayam")

Well - you are correct and it won’t recognize it via developer F12 tools.  
In such case it strange it recognizes it when i define as a TO in Object Repositiory.

![](https://s3.amazonaws.com/katalon-forum/editor/9m/qjcg79e81n5i.png "Image: https://s3.amazonaws.com/katalon-forum/editor/9m/qjcg79e81n5i.png")  
Thank you!  
Andrew

[TO-xpath-manual.png](https://s3.amazonaws.com/katalon-forum/editor/9m/qjcg79e81n5i.png)

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 22, 2018, 4:06pm UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/6 "2018-06-22T16:06:24Z")

</div>

> kazurayam said:
> 
> Andrew,
> 
> I think you need to make sure your xpath is valid. You do not need Katalon Studio to verify your xpath. You should get used to alternative xpath tool. Google Chrome and Firefox has built-in function. See
> 
> - [Chrome DevTools - Chrome for Developers](https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference)
> 
> Try the following steps:
> 
> 1. Open Chrome and navigate to your target URL  
> 2. Press F12 to open up Chrome DevTools  
> 3. Switch to Console pane  
> 4. Type
> 
> ```auto
> $x("//a[@href='http://clickplus103.com/clk.trk?CID=410486&AFID=423399&dwi_e=8a4030fb-3dec-4cf2-8de8-ed059b79b454']")
> 
> ```
> 
> 5. Check if the xpath expression selects what you intended or not.

Kazurayam,

OK - at this point when i run this in Chrome Dev tools console - the link being recognized.

document.querySelector(“a[href=‘[http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604](http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604)’]”)

However it still won’t recognize it during the run.

![](https://s3.amazonaws.com/katalon-forum/editor/90/x769koksskua.png)

_com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Link in the email’ located by 'By.xpath: //a[href='[http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604’\]’](http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604'%5C%5D') not found_

Note:  
If i run this in console it says it is invalid function:  
**_$x(“//a[@href=‘[http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604](http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604)’]”)_**

Uncaught TypeError: this.oj.apply is not a function

Thank you  
Andrew

[Console-Verify.png](https://s3.amazonaws.com/katalon-forum/editor/90/x769koksskua.png)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 25, 2018, 1:32am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/7 "2018-06-25T01:32:46Z")

</div>

Andrew,

You should be aware which technology you are using: CSS selector or XPath.

-----------

You reported the following command succeeded:

```auto
document.querySelector("a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']")

```

The document.querySelector function accepts a string argument, which is interpreted **as a CSS Selector** (not as a XPath). See [https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)

Your string

```auto
a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']

```

is a valid CSS Selector; it selects **element with a href attribute of the specified value**.

 

--------------------

 

Howerver,

 

> _com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Link in the email’ located by 'By.xpath: //a[href='`http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']'` not found_

 

this messages tells me that you are asking Katalon to interprete your string

 

```auto
a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']

```

 

**as a XPath** expression. Beware, your string is invalid as a XPath expression. Why invalid? Let me interprete this string as a XPath:

 

- The root element of your target should be (this is never the case. you should rather write ‘//a’ to seek for in the document)

 

- You want to select element(s) which has a child element. (this is never the case. in the Hyper Text Markup Languge specificication, there is no element defined.)

 

- a[href=“…”] is not legal as XPath syntax. Rather you may write a[href/text()=‘…’], which is syntactically correct, but would select nothing.

 

-------------------------------------

 

You have a few choices:

 

1. Change your Test Obect ‘Link in the email’; of which selector now has ‘xpath’. Change from ‘xpath’ to ‘css’. I mean, you can tell your Test Object ‘Link in the email’ to interprete your string as CSS selector, rather than XPath expression.

 

or

 

2. Keep you Test Object ‘Link in the email’ to interprete you string as a xpath expression; and change your string to be a valid XPath expression. I would presume the following string is a valid xpath for you.

 

```auto
//a[@href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']

```

 

-----------------------------------

 

> If i run this in console it says it is invalid function:  
> \*\*\_$x(“//a[[@href='](http://forum.katalon.com/profile//href%3D%27)[http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604’]](http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604%27%5D)”)  
> \_\*\*Uncaught TypeError: this.oj.apply is not a function

I tried a similar $x() against the GMail page in the Chrome’s DevTool, I encountered Uncaught TypeError as well. I do not know why.

I tried $x tool in the Firefox’ F12 dev tool, and it functioned well.

So you should rather use Firefox instead of Chrome for XPath verification by $x() function

When I open other URLs in Chrome and tried DevTools $x, it functioned OK. Wow. This makes me guess that the GMail page is a very special case for $x. $x seems getting somewhat confused with the GMail page and can not deal with properly.

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 25, 2018, 9:56pm UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/8 "2018-06-25T21:56:05Z")

</div>

> kazurayam said:
> 
> Andrew,
> 
> You should be aware which technology you are using: CSS selector or XPath.
> 
> -----------
> 
> You reported the following command succeeded:
> 
> ```auto
> document.querySelector("a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']")
> 
> ```
> 
> The document.querySelector function accepts a string argument, which is interpreted **as a CSS Selector** (not as a XPath). See [https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
> 
> Your string
> 
> ```auto
> a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']
> 
> ```
> 
> is a valid CSS Selector; it selects **element with a href attribute of the specified value**.
> 
>  
> 
> --------------------
> 
>  
> 
> Howerver,
> 
>  
> 
> > _com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Link in the email’ located by 'By.xpath: //a[href='`http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']'` not found_
> 
>  
> 
> this messages tells me that you are asking Katalon to interprete your string
> 
>  
> 
> ```auto
> a[href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']
> 
> ```
> 
>  
> 
> **as a XPath** expression. Beware, your string is invalid as a XPath expression. Why invalid? Let me interprete this string as a XPath:
> 
>  
> 
> - The root element of your target should be (this is never the case. you should rather write ‘//a’ to seek for in the document)
> 
>  
> 
> - You want to select element(s) which has a child element. (this is never the case. in the Hyper Text Markup Languge specificication, there is no element defined.)
> 
>  
> 
> - a[href=“…”] is not legal as XPath syntax. Rather you may write a[href/text()=‘…’], which is syntactically correct, but would select nothing.
> 
>  
> 
> -------------------------------------
> 
>  
> 
> You have a few choices:
> 
>  
> 
> 1. Change your Test Obect ‘Link in the email’; of which selector now has ‘xpath’. Change from ‘xpath’ to ‘css’. I mean, you can tell your Test Object ‘Link in the email’ to interprete your string as CSS selector, rather than XPath expression.
> 
>  
> 
> or
> 
>  
> 
> 2. Keep you Test Object ‘Link in the email’ to interprete you string as a xpath expression; and change your string to be a valid XPath expression. I would presume the following string is a valid xpath for you.
> 
>  
> 
> ```auto
> //a[@href='http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604']
> 
> ```
> 
>  
> 
> -----------------------------------
> 
>  
> 
> > If i run this in console it says it is invalid function:  
> > \*\*\_$x(“//a[[@href='](http://forum.katalon.com/profile//href%3D%27)[http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604’]](http://clickplus103.com/clk.trk?CID=413000&AFID=423399&ADID=2103604%27%5D)”)  
> > \_\*\*Uncaught TypeError: this.oj.apply is not a function
> 
> I tried a similar $x() against the GMail page in the Chrome’s DevTool, I encountered Uncaught TypeError as well. I do not know why.
> 
> I tried $x tool in the Firefox’ F12 dev tool, and it functioned well.
> 
> So you should rather use Firefox instead of Chrome for XPath verification by $x() function
> 
> When I open other URLs in Chrome and tried DevTools $x, it functioned OK. Wow. This makes me guess that the GMail page is a very special case for $x. $x seems getting somewhat confused with the GMail page and can not deal with properly.

Hi [kazurayam](http://forum.katalon.com/profile/4280/kazurayam)

Actually i have several updates since the last several days.

You are correct with xpath syntax provided and this was my mistake.  
Here is what worked (in case someone else needs to address same question):

//a[@href=‘ **url** ’]

Here is the exact part of the code:

def EmailPath = new TestObject(“Link in the email”)

def exprURL = data.internallyGetValue(“xPath”, reverse)

EmailPath.addProperty(“xpath”, ConditionType.EQUALS, exprURL)

WebUI.verifyElementPresent(EmailPath, 10, FailureHandling.STOP\_ON\_FAILURE)

WebUI.click(EmailPath)

I also had to add some logic for the going thru emails sent and order they are arrived.  
Not perfect but it works for now. Let me know if you have a better or precise solution.

Problem to Resolve:

Emails sent from the .csv in this order:  
- email 1  
- email 2  
- email \*\*n

\*\*Emails shown in opposite order in the Inbox:  
- email **n**  
- email 2  
- email 1  
I used the same .csv and same loop. Just have 2 variables. One starts from the 1st row of the file and increments all the way to the last record in the file. The other variable works in opposite direction.  
Probably trivial for many advance folks here, but i did it by myself and first time.

Thank you for all your guidance!  
Andrew

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 26, 2018, 6:47am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/9 "2018-06-26T06:47:59Z")

</div>

Andrew,

> Let me know if you have a better or precise solution.

Please have a look at the following tips:

[http://forum.katalon.com/discussion/7578/a-custom-keyword-which-returns-a-list-of-selenium-webelement-from-a-web-page?new=1](http://forum.katalon.com/discussion/7578/a-custom-keyword-which-returns-a-list-of-selenium-webelement-from-a-web-page?new=1)

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 27, 2018, 1:40am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/10 "2018-06-27T01:40:24Z")

</div>

> kazurayam said:
> 
> Andrew,
> 
> > Let me know if you have a better or precise solution.
> 
> Please have a look at the following tips:
> 
> [http://forum.katalon.com/discussion/7578/a-custom-keyword-which-returns-a-list-of-selenium-webelement-from-a-web-page?new=1](http://forum.katalon.com/discussion/7578/a-custom-keyword-which-returns-a-list-of-selenium-webelement-from-a-web-page?new=1)

Good Evening [kazurayam](http://forum.katalon.com/profile/4280/kazurayam)

I reviewed your solution. Also downloaded and executed and i think i understand and could follow.  
Anyways - if you feel it is a different topic, i can create one.

Seems it resolve the problem on the single element validation (multiple data).  
Here is the case below and i feel it will require different approach.

I have a table that has withing sub-table with multiple columns and rows. Well, i care only about 3 columns (per row).

![](https://s3.amazonaws.com/katalon-forum/editor/m1/v2rck6yhldgt.png)  
Expected\_Result (string) = “_415074 Money Map Press (Crypto C)… 1_”.

The goal is to read the values from each row (from the above 3 columns) also into a string.  
Say Actual\_Result.

Here is the xpath for each item:

/html/body/table/tbody/tr[1]/td/div/div[8]/div/table/tbody/tr[6]/td[3]

/html/body/table/tbody/tr[1]/td/div/div[8]/div/table/tbody/tr[6]/td[4]/div/div/a

/html/body/table/tbody/tr[1]/td/div/div[8]/div/table/tbody/tr[6]/td[7]/a

And this is where i’m lost

```auto
List<String> cs = CustomKeywords.'com.kazurayam.ksbackyard.FindElementsByXPath.getElementContentsAsList'('//select[@name="facility"]/option')
for (int i = 0; i < cs.size(); i++) {
    WebUI.verifyEqual(cs[i], expectedContents[i])} 

```

Thank you  
Andrew

[Table-Row-As-String-Verify.png](https://s3.amazonaws.com/katalon-forum/editor/m1/v2rck6yhldgt.png)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 27, 2018, 2:05am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/11 "2018-06-27T02:05:11Z")

</div>

Please try the following snippet as a Test Case

```auto
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
List<Map<String,String> expectedContents = [
    ["CID":"415074", "Campain":"Money Map Press", "Clicks":"1"]
]
List<WebElement> trList = CustomKeywords. 'com.kazurayam.ksbackyard.FindElementsByXPath.getWebElementsAsList'( '/html/body/table/tbody/tr[1]/td/div/div[8]/div/table/tbody/tr')
for (int i = 0; i < trList.size(); i++) {
    String cid = trList[i].findElement(By.xpath('td[3]')).getText()
    String campain = trList[i].findElement(By.xpath('td[4]/div/div/a')).getText()
    String clicks = trList[i].findElement(By.xpath('td[7]/a')).getText()
    WebUI.verifyEqual(cid, expectedContents[i].CID)
    WebUI.verifyEqual(campain, expectedContents[i].Campain)
    WebUI.verifyEqual(clicks, expectedContents[i].Clicks)
}

```

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 27, 2018, 3:08am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/12 "2018-06-27T03:08:47Z")

</div>

> kazurayam said:
> 
> Please try the following snippet as a Test Case
> 
> ```auto
> import org.openqa.selenium.By
> 
> ```

import org.openqa.selenium.WebElement  
List\<Map\<String,String\> expectedContents = [  
[“CID”:“415074”, “Campain”:“Money Map Press”, “Clicks”:“1”]  
]  
List trList = CustomKeywords. ‘com.kazurayam.ksbackyard.FindElementsByXPath.getElementContentsAsList’( ‘/html/body/table/tbody/tr[1]/td/div/div[8]/div/table/tbody/tr’)  
for (int i = 0; i \< trList.size(); i++) {  
String cid = trList[i].findElement(By.xpath(‘td[3]’)).getText()  
String campain = trList[i].findElement(By.xpath(‘td[4]/div/div/a’)).getText()  
String clicks = trList[i].findElement(By.xpath(‘td[7]/a’)).getText()  
WebUI.verifyEqual(cid, expectedContents[i].CID)  
WebUI.verifyEqual(campain, expectedContents[i].Campain)  
WebUI.verifyEqual(clicks, expectedContents[i].Clicks)  
}

> ```auto
> 
>   
>   
> 
>   
> 
> ```

Thank you [kazurayam](http://forum.katalon.com/profile/4280/kazurayam)!

It won’t execute because of \*\*\_because (of) java.lang.ClassNotFoundException: com.kazurayam.ksbackyard.FindElementsByXPath

\_\*\*I found the class source code you listed in the other post, but still get this error.  
I will have to figure out why it won’t let me even including \*\*package com.kazurayam.ksbackyard

\*\*Thank you!  
Andrew

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 27, 2018, 3:57am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/13 "2018-06-27T03:57:17Z")

</div>

This screenshot shows how the source code of the com.kazurayam.ksbackyard.FindElementsByXPath is laid in my environment  
 ![](https://s3.amazonaws.com/katalon-forum/editor/91/im9a271i1en3.png "Image: https://s3.amazonaws.com/katalon-forum/editor/91/im9a271i1en3.png")

[17864.png](https://s3.amazonaws.com/katalon-forum/editor/91/im9a271i1en3.png)

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 27, 2018, 9:31pm UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/14 "2018-06-27T21:31:44Z")

</div>

> [kazurayam](https://forum.katalon.com/profile/4280/kazurayam) said:
> 
> This screenshot shows how the source code of the com.kazurayam.ksbackyard.FindElementsByXPath is laid in my environment  
> ![](https://s3.amazonaws.com/katalon-forum/editor/91/im9a271i1en3.png "Image: https://s3.amazonaws.com/katalon-forum/editor/91/im9a271i1en3.png")

Thank you Kazurayam!

Trying it now…

Andrew

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 28, 2018, 1:12am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/15 "2018-06-28T01:12:07Z")

</div>

> kazurayam said:
> 
> This screenshot shows how the source code of the com.kazurayam.ksbackyard.FindElementsByXPath is laid in my environment  
> ![](https://s3.amazonaws.com/katalon-forum/editor/91/im9a271i1en3.png)

Kazurayam

I have your entire class in the “FindElementsByXPath.groovy”.

But the test fails on this line within the loop:

_**String cid = trList[i].findElement(By.xpath(‘td[3]’)).getText()**_

```
...cid = trList\[i\].findElement(org.openqa.selenium.By.xpath("td\[3\]")).getText()  

```

_“groovy.lang.MissingMethodException: No signature of method: java.lang.String.findElement() is applicable for argument types: (org.openqa.selenium.By$ByXPath) values: [By.xpath: td[3]]”_

I have tried to make changes in the above section, but no luck.

Appreciate!!  
Andrew

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 28, 2018, 2:20am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/16 "2018-06-28T02:20:39Z")

</div>

I guess you have

```auto
List<String> trList = CustomKeywords.....................

```

This is wrong.  
`trList` must be an instance of `List<WebElement>`, not `List<String>`.

So, change it to:

```auto
List<WebElement> trList = CustomKeywords...................

```

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://forum.katalon.com/u/Andrew)\
**Post date:** [June 28, 2018, 2:27am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/17 "2018-06-28T02:27:23Z")

</div>

> kazurayam said:
> 
> I guess you have
> 
> ```auto
> List<String> trList = CustomKeywords.....................
> 
> ```
> 
> This is wrong.  
> `trList` must be an instance of `List<WebElement>`, not `List<String>`.
> 
> So, change it to:
> 
> ```auto
> List<WebElement> trList = CustomKeywords...................
> 
> ```

Kazurayam

I have this:

List trList = CustomKeywords.

```
'com.kazurayam.ksbackyard.FindElementsByXPath.getElementContentsAsList'(

    '/html/body/table/tbody/tr\[1\]/td/div/div\[8\]/div/table/tbody/tr')  

```

![](https://s3.amazonaws.com/katalon-forum/editor/ak/icxpn9c8yhvc.png "Image: https://s3.amazonaws.com/katalon-forum/editor/ak/icxpn9c8yhvc.png")

Thank you  
Andrew

[debug062718.png](https://s3.amazonaws.com/katalon-forum/editor/ak/icxpn9c8yhvc.png)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 28, 2018, 6:59am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/18 "2018-06-28T06:59:14Z")

</div>

Andrew,

I made one more GitHub repository which demonstrates how to make use of a List\<org.openqa.selenium.WebElement\> in a Katalon test case. See

> **[A custom keyword which returns a List of Selenium WebElement from a Web page](http://forum.katalon.com/discussion/7578/a-custom-keyword-which-returns-a-list-of-selenium-webelement-from-a-web-page?new=1)**
>
> \# Defining a problem Let me define a problem with a simple HTML as target.

or directly

> **[kazurayam/KatalonDiscussion7520](https://github.com/kazurayam/KatalonDiscussion7520)**
>
> Contribute to kazurayam/KatalonDiscussion7520 development by creating an account on GitHub.

I intended this new example to be informative for you.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 28, 2018, 7:02am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/19 "2018-06-28T07:02:40Z")

</div>

Andrew,

> _“groovy.lang.MissingMethodException: No signature of method: java.lang.String.findElement() is applicable for argument types: (org.openqa.selenium.By$ByXPath) values: [By.xpath: td[3]]”_

It is difficult for me to find an answer straight to your problem because I do not have access to your Application Under Test and your codes. Please have a look at my new study mentioned above. I hope my study may give you a clue.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 29, 2018, 5:06am UTC](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662/20 "2018-06-29T05:06:42Z")

</div>

Andrew,

I thought I can abstract your requirement to a simpler case. You just want to iterate over a elements and elements of a : 2 dimensional iteration.

Then there is a much simpler approach. You do not need to study **org.openqa.selenium.WebElement**. You just want to use [Parameterized Test Object](https://docs.katalon.com/pages/viewpage.action?pageId=12419075) in Katalon Studio.

The [Web Page](http://demoaut-mimic.kazurayam.com/7520_simpler_testbed.html) as testbed is like this:  
 ![](https://s3.amazonaws.com/katalon-forum/editor/74/43z4vxiy2b8w.png)

```auto
<html>
<body>
    <table class="table">
        <thead>
            <tr><th>found</th><th>A</th><th>B</th><th>C</th></tr>
        </thead>
        <tbody>
            <tr><th>1</th><td>A1</td><td><span>B1</span></td><td><a href="#">C1</a></td></tr>
            <tr><th>2</th><td>A2</td><td><span>B2</span></td><td><a href="#">C2</a></td></tr>
            <tr><th>3</th><td>A3</td><td><span>B3</span></td><td><a href="#">c3</a></td></tr>
        </tbody>
    </table>
</div>
</body>
</html>

```

I made a test case is like this:

```auto
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.openBrowser('')
WebUI.setViewPortSize(703, 347)
WebUI.navigateToUrl('http://demoaut-mimic.kazurayam.com/7520_simpler_testbed.html')
WebUI.verifyElementPresent(findTestObject('Page_Discussion 7520/table'),
    10, FailureHandling.STOP_ON_FAILURE)
List<List<String>> expectedContents = [
    ["A1", "B1", "C1"],
    ["A2", "B2", "C2"],
    ["A3", "B3", "C3"],
]
for (int i = 0; i < expectedContents.size(); i++) {
    for (int j = 0; j < expectedContents[i].size(); j++) {
        String cellValue = WebUI.getText(findTestObject(
            'Page_Discussion 7520/cell', ['trIndex':i + 1, 'tdIndex':j + 1]))
        WebUI.verifyEqual(expectedContents[i][j], cellValue)
    }
}
WebUI.closeBrowser()

```

I wanted to check if the Web page displays A1, B1, C1, A2, B2, C2, A3, B3, C3 in table as I wrote in the testcase.

I made a Test Object ‘Page\_Discussion 7520/cell’ like this:

![](https://s3.amazonaws.com/katalon-forum/editor/zt/6rnsg6fbmxhz.png)  
Please note this Test Object has such XPath as selector:

```auto
//table/tbody/tr[${trIndex}]/td[${tdIndex}]

```

${trIndex} is the place holder for the index of the

 elements in the 

|
| |

.  
${tdIndex} is the place holder for the index of the .

These place holders will be interpolated by the Test Case runtime.  
When executed, I got following log:

```auto
[INFO] - Found 1 web elements with id: 'Object Repository/Page_Discussion 7520/cell' located by 'By.xpath: //table/tbody/tr[1]/td[1]' in '30' second(s)
...
[PASSED] - Text of object 'Object Repository/Page_Discussion 7520/cell' is: 'A1'
...
[INFO] - Found 1 web elements with id: 'Object Repository/Page_Discussion 7520/cell' located by 'By.xpath: //table/tbody/tr[1]/td[2]' in '30' second(s)
...
[INFO] - Found 1 web elements with id: 'Object Repository/Page_Discussion 7520/cell' located by 'By.xpath: //table/tbody/tr[1]/td[3]' in '30' second(s)
...
[PASSED] - Text of object 'Object Repository/Page_Discussion 7520/cell' is: 'C1'
...
[INFO] - Found 1 web elements with id: 'Object Repository/Page_Discussion 7520/cell' located by 'By.xpath: //table/tbody/tr[3]/td[3]' in '30' second(s)
...
[FAILED] - Unable to verify equal between actual object 'C3' and expected object 'c3' (Root cause: Actual object 'C3' and expected object 'c3' are not equal)

```

I expected ‘C3’ but the page displayed ‘c3’, therefore the test case failed.

You can clone out this demo form GitHub repository: [GitHub - kazurayam/KatalonDiscussion7520](https://github.com/kazurayam/KatalonDiscussion7520) and see Test Case ‘TC2’

**# Disucssion**

Paremetarizing feature of Test Object is flexible enough; You can make more deeply nested iteration. You can write as many dimensional parameterized XPath expression as you want.

For example, if you have 2 or more in the target page, you need 3 dimensional parameterized XPath like this:

```auto
//table[$tblIndex]/tbody/tr[${trIndex}]/td[${tdIndex}]

```

or if you have a table which contains inner tables, you need 4 dimensional parameterized XPath like this:

```auto
//table[@id="T1"]/tbody/tr[${outerTrIndex}]/td[${outerTdIndex}]//table/tbody/tr[${innerTrIndex}]/td[${innerTdIndex}]

```

# Performance issue

The above approach has a performance issue. It make frequent call to WebUI.getText(TestObject). Every single WebUI.getText() makes a request/reply session between Katalon Studio and Browser. It can be very slow.  
If you find this approach too slow, then you should look at using

List WebUI.findWebElements(TestObject)

[https://api-docs.katalon.com/com/kms/katalon/core/webui/keyword/WebUiBuiltInKeywords.html#findWebElements(TestObject,%20int)](https://api-docs.katalon.com/com/kms/katalon/core/webui/keyword/WebUiBuiltInKeywords.html#findWebElements(TestObject,%20int))

[testobject\_cell.png](https://s3.amazonaws.com/katalon-forum/editor/zt/6rnsg6fbmxhz.png)

[7520.PNG](https://s3.amazonaws.com/katalon-forum/editor/74/43z4vxiy2b8w.png)

| elements in a |
|
| |

[Next page](https://forum.katalon.com/t/the-xpath-for-the-url-is-correct-but-not-visible-if-added-via-addproperty/11662.md?page=2)
