Hi, I keep getting the [object Object] and I’m not sure how to fix this. I was trying to compare values Katalon Recorder.
Hi there, and thanks for posting in the Katalon community!
To help you faster, please review our guide on Katalon Recorder here: Katalon Recorder overview | Katalon Docs. Double-checking the steps and configurations might resolve the issue.
If the doc doesn’t help, feel free to provide more details, and a community member will assist you soon. Thanks for being a part of our community!
Best,
Albert Le
When using if statements in Katalon Recorder, you might encounter the [object Object]
error if you’re not properly comparing values. Here’s how to fix it:
1. Store Values Correctly
Use storeText
, storeValue
, or storeAttribute
to save the value you want to compare into a variable. For example:
Command: storeText
Target: css=#elementId
Value: myVar
2. Use runScript
for Conditional Logic
Katalon Recorder uses JavaScript for conditionals. Use runScript
with the following syntax:
Command: runScript
Target: return ${myVar} === "expectedValue" // Replace with your comparison
3. Example Workflow
Here’s a step-by-step example to compare two values:
- Store the first value:
Command: storeText
Target: css=#element1
Value: var1
- Store the second value:
Command: storeText
Target: css=#element2
Value: var2
- Compare the values:
Command: runScript
Target: return ${var1} === ${var2} // Compare variables directly
- Add conditional logic:
Command: if
Target: javascript{storedVars.var1 === "Expected Text"} // Use storedVars to access variables
Value: // Leave empty
4. Avoid [object Object]
Errors
- Ensure you’re not storing WebElement objects (e.g., use
storeText
instead ofstore
). - Trim whitespace if needed:
Target: return ${myVar}.trim() === "expected"
- Convert to numbers for numeric comparisons:
Target: return parseInt(${myVar}) === 42
5. Debugging Tips
- Use
echo
to print variables:
Command: echo
Target: ${myVar}
- Check if elements exist before storing values (use
verifyElementPresent
).
Full Example
Command | Target | Value
---------------------------------------------------
storeText | css=#price | price
storeText | css=#expectedPrice | expectedPrice
runScript | return ${price} === ${expectedPrice} |
if | javascript{storedVars.price === "100"} |
echo | Prices match! |
endIf | |
This should resolve the [object Object]
error and let you compare values properly. Let me know if you need more details!
@samuelyong91 your query resolved?
Hi, sorry for the late reply
In my case, I wasn’t comparing two text elements, I was comparing a text element with a bit of text that I put in manually: {$couponMsg} == Successfully Redeemed spam test.
However, it will return the [object Object] error.
i think, you have to use following syntax: if | “${couponMsg}” == “Successfully Redeemed spam test” |