How to verify that a given textbox field is enabled or not on a webpage

Hi Experts, need some advice
In the attached image, on the right-side, you will see 3 textboxes with placeholders like Company, Username, and Password
Now, I have scripted in order to verify →

  1. Textbox for Company field is available
  2. The field is enabled [i.e., editable]
  3. Then verify the placeholder text [i.e., grey color text]; ‘Company’, is displayed
  4. And then enter the value for Company in the textbox field

The issue is in the 2nd step; where-in, I try to verify the textbox for Company field is enabled / clickable
It is not going inside the ‘if-condition’ and is failing at the line where I have declared the boolean variable [refer //Step2 in the attached code]

Below is the code for your reference →

TestObject Company_textField = findTestObject('x')

//Step1 -> Verify if the text-box field for Company is present
boolean isElementPresent_Company_textField = WebUI.verifyElementPresent(Company_textField, 10)	
	if(isElementPresent_Company_textField)
	{
		println("Company text field is available")
	}
	else
	{
			KeywordUtil.markFailedAndStop("Company field was not found, hence, terminating the execution")
	}

//Step2 -> Verify if the text-box field for Company is enabled [i.e., editable or not]	
boolean isElementPresent_Company_clickable = WebUI.verifyElementClickable(Company_textField, 10)
	if(isElementPresent_Company_clickable)
	{
		println("Company text field is editable")
	}
	else
	{
		KeywordUtil.markFailedAndStop("Company field was not editable, hence, terminating the execution")
	}

//Step3 -> Verify if the placeholder text [i.e., the grey color text 'Company'] is displayed in the text-box field for Company
	String expectedPlaceholder_Company = 'Company'
	String actualPlaceholder_Company = WebUI.getAttribute(Company_textField, 'placeholder')
	if(expectedPlaceholder_Company == actualPlaceholder_Company)
	{
		WebUI.setText(Company_textField, "XYZ") //Step4 -> Entering the value for Company field, after all the conditions are satisfied
	}
	else
	{
		KeywordUtil.markFailedAndStop("The grey colored text 'Company' was not found in the Company's text field, hence, terminating the execution")
	}

Can anyone take a look and clarify

Many Thanks

2 Likes

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

Perhaps you should make sure your element is present on the page first before you do your tests.
Edit: also, the method “verifyElementClickable” only has one parameter, or two if you have the “FailureHandling” option, not the timeOut.

WebUI.waitForElementVisible(Company_textField, 10)

boolean isElementPresent_Company_clickable = WebUI.verifyElementClickable(Company_textField)
if(isElementPresent_Company_clickable)
{
println("Company text field is editable")
}
else
{
KeywordUtil.markFailedAndStop("Company field was not editable, hence, terminating the execution")
}

or, if you want to simplify your whole statements, just add the “FailureHandling” option onto your statement and not have the “if/else” condition.

import com.kms.katalon.core.model.FailureHandling as FailureHandling

WebUI.waitForElementVisible(Company_textField, 10)

WebUI.verifyElementClickable(Company_textField, FailureHandling.STOP_ON_FAILURE)
1 Like

kindly format your codesnippet for easy readibility (like grylion54’s reply post)

1 Like

Hi @anandkumar.venkatara, Please see this guide to formatting your posts for clearer understanding. Discourse Guide: Code Formatting - Meta - Stonehearth Discourse

1 Like

Hi grylion54
Thanks, I have added WebUI.waitForElementVisible(Company_textField, 10)
But it is resulting in groovy.lang.MissingMethodException error

// Verify Company field is present; enabled [in order to enter the Company name], and the placeholder 'Company', and if not, terminate the execution
TestObject Company_textField = findTestObject('x')
WebUI.waitForElementVisible(Company_textField, 10)
//Step1 -> Verify if the text-box field for Company is present
	boolean isElementPresent_Company_textField = WebUI.verifyElementPresent(Company_textField, 10)	
	if(isElementPresent_Company_textField)
	{
		println("Company text field is available")
	}
	else
	{
			KeywordUtil.markFailedAndStop("Company field was not found, hence, terminating the execution")
	}

//Step2 -> Verify if the text-box field for Company is enabled [i.e., editable or not]
	println("Test--1 July 22 2024")
	boolean isElementPresent_Company_clickable = WebUI.verifyElementClickable(Company_textField, 10)
	println("Test--2 July 22 2024")
	if(isElementPresent_Company_clickable)
	{
		println("Company text field is editable")
	}
	else
	{
		KeywordUtil.markFailedAndStop("Company field was not editable, hence, terminating the execution")
	}

Pls. note →
For test-purposes, I have given 2 println statements → one; before declaring the boolean variable, and another, after declaring the boolean variable
However, when I verify in the console, I see that the one before declaring the boolean variable is showing-up, and the other one isn’t, which means, something incorrect with the boolean variable’s declaration

Many Thanks

1 Like

As I mentioned in my post above, there is no “timeOut” for the statement, “verifyElementClickable”. The correct format for the statement is:
WebUI.verifyElementClickable(Company_textField)

That is the reason for your “MissingMethodException” error.

Just so you know:

or, if you did not need to use your “if/else”, then you can add the FailureHandling option.

import com.kms.katalon.core.model.FailureHandling as FailureHandling

WebUI.verifyElementClickable(Company_textField, FailureHandling.STOP_ON_FAILURE)

Edit: MissingMethodException either indicates that you don’t have the correct number of parameters or you do not have the correct data type of the parameters for the method. Because of these errors, Katalon cannot match/find the method you want to use.
In your case above, you don’t have the correct number of parameters for the method. Remove the “10” (i.e. the timeOut) from the format you have.

Thanks grylion54, it worked

1 Like

Hi folks, :wave:

As this topic has been solved, we will proceed to close it shortly.

Should you have any other question, or still encounter similar issues, please feel free to create another thread.

Thanks,
Albert

This topic was automatically closed after 15 hours. New replies are no longer allowed.