Variable not receiving value from javascript

Yup, I see it. He needs to just use a simple for loop.

@Jeff_Sharp I think Russ has identified the issue; you need to use a normal for loop as he’s suggested. Try the JS code that he has provided and get back to us, thanks.

Jeff,
just one question, why the hell are you using such code?
you have selector, you have forEach loop, some condition and you are trying to get innerHtml of some cell … this can be quite nicely implemented using what Katalon already offers : Selenium and java/groovy…
maybe there is an reason however, i’m not able to see it …

1 Like

@Andrej_Podhajsky makes a fair and valid point. I guess JS is my hammer, and everything looks like a nail :blush:

No, it can’t be nicely implemented using what Katalon already offers, unless I’m missing something. The problem is that the rows in the table are assigned different identifiers/locators each time an account is created. Therefore I can’t easily identify the element each time I run the test, since the ID’s/etc will be different. Also, I need to verify that the Duration (see my example screenshot above in this thread) for each line item is correct. However, for some users there will be rows of data that do not need to be verified. So I need to first verify that a specific row needs the Duration verified and then to verify that Duration to make sure it matches what is expected. I could not figure out how to do this using what Katalon Studio provides, which is why the developer I asked about this suggested using Javascript and provided me with the code. According to Russ, that code is incorrect so I’m trying to use JS that actually does what I need it to do. One problem, however, is that I am not a Javascript developer so I don’t understand most of what Russ has explained or suggested. I’m turning this over to the developer that tried to help me earlier in hopes that she can figure all of this out. Hope that helps you understand what I’m trying to do.

now i’ll be a bit stubborn, let me think in ‘Katalonian’ for second…

  1. there is keyword that executes and returns value (shameless self promo) Execute xpath functions from Katalon Studio try to get inspiration in implementation
  2. what you need: number of all rows in table that contains text we need (don’t need id of row) - should be easy to build xpath for such query
  3. for loop to go thru all interested rows and check for column you are interested in using parameterized xpath
  4. assert return from WebUI.getText() expected value.

this would be my approach…

1 Like

to show what i’m talking about:

<table id='getVariable'>
			<tbody>
				<tr><td>0001</td><td>xxx-text to recognize</td><td>1975</td><td>other column</td></tr>
				<tr><td>0001</td><td>yyy-text to recognize</td><td>1975</td><td>other column</td></tr>
				<tr><td>0001</td><td>zzz-text to recognize</td><td>1975</td><td>other column</td></tr>
				<tr><td>0001</td><td>xxx-text to recognize</td><td>1977</td><td>other column</td></tr>
				<tr><td>0001</td><td>qqq-text to recognize</td><td>1975</td><td>other column</td></tr>
				<tr><td>0001</td><td>www-text to recognize</td><td>1975</td><td>other column</td></tr>
			</tbody>
		</table>

def of objects in OR:
rows to check:

rows to check assert

code:

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

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

WebUI.openBrowser('file://C:/Users/XXXXX/src/html/hello.html')

def noOfRowsToCheck = CustomKeywords.'com.swre.tools.exexpath'(findTestObject('Object Repository/__Sandbox/HelloFile/rowsToCheck'), 'NUMBER_TYPE')

println noOfRowsToCheck

for (i = 1; i <= noOfRowsToCheck; i++){
	println WebUI.getText(findTestObject('Object Repository/__Sandbox/HelloFile/rowsToCheckAssert',[('INDEX'):i]))
}

console:

2019-04-24 08:06:22.587 DEBUG testcase.value check in table            - 1: openBrowser("file://C:/Users/XXXXXX/src/html/hello.html")
2019-04-24 08:06:24.581 DEBUG testcase.value check in table            - 2: noOfRowsToCheck = com.swre.tools.exexpath(findTestObject("Object Repository/__Sandbox/HelloFile/rowsToCheck"), "NUMBER_TYPE")
2019-04-24 08:06:24.825 DEBUG testcase.value check in table            - 3: println(noOfRowsToCheck)
2
2019-04-24 08:06:24.832 DEBUG testcase.value check in table            - 4: for ([i = 1, i <= noOfRowsToCheck, (i++)])
2019-04-24 08:06:24.835 DEBUG testcase.value check in table            - 1: println(getText(findTestObject("Object Repository/__Sandbox/HelloFile/rowsToCheckAssert", ["INDEX":i])))
1975
2019-04-24 08:06:24.993 DEBUG testcase.value check in table            - 1: println(getText(findTestObject("Object Repository/__Sandbox/HelloFile/rowsToCheckAssert", ["INDEX":i])))
1977