How to get the default value of input field

Hello!

I would like to ask for help because I want to verify that the default value of the input text field is correct. I used this syntax WebUI.getAttribute(findTestObject(‘Shopping_Cart/Quantity_Textbox’), 1), and I got an error below.

This is the actual UI

JPetStore Demo 2021-10-16 at 12.32.45 PM

=============== ROOT CAUSE =====================

For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html

================================================

10-16-2021 12:27:09 PM getAttribute(findTestObject(“Shopping_Cart/Quantity_Textbox”), 1)

Elapsed time: 0.208s

Test Cases/TC-002 FAILED.

Reason:

groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getAttribute() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.lang.Integer) values: [TestObject - ‘Object Repository/Shopping_Cart/Quantity_Textbox’, …]

Possible solutions: getAttribute(com.kms.katalon.core.testobject.TestObject, java.lang.String), getAttribute(com.kms.katalon.core.testobject.TestObject, java.lang.String, com.kms.katalon.core.model.FailureHandling)

at TC-002.run(TC-002:66)

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:430)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:421)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:400)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:392)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:273)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1634358373663.run(TempTestCase1634358373663.groovy:25)

Read the document carefully to find out how to call the keyword appropriately:

You need to read the HTML source of your web page. In order to see the HTML source, you need to use Chrome DevTools. Read the following post,

especially,

8. Learn to Use DevTools.
Finally, many of the points above rely on YOU understanding how to use the Browser Developer Tools (aka DevTools ).

The default value of an <input> element is possibly contained as a value attribute.

https://www.w3schools.com/tags/att_input_value.asp

Thanks @kazurayam, It works now. I used this syntax WebUI.getAttribute(findTestObject(‘Shopping_Cart/Quantity_Textbox’), ‘value’). But I’m not sure if I used correct syntax. Just to add a context, My goal is I want to ensure that the default value of the input field (the default quantity value in the actual UI is “2”) is correct. Is there another web keyword should I use? Thank you!

def v = WebUI.getAttribute(findTestObject(‘Shopping_Cart/Quantity_Textbox’), ‘value’)
assert v == "2"

Hi @kazurayam Thanks for you response! I tried but I have an error :frowning:

Your code is not the same as mine.
You made a mistake.
Review your code carefully.

Sorry @kazurayam. It’s working now. Thank you for always helping me! :slight_smile: