How to check the mandatory field?

i want to check element which is mandatory or not kindly help me to resolve this issue

There are many ways that a field can be set as mandatory. Can you show us an example of how your company sets yours? As an example, in the image below, the red asterisk is how we show a mandatory field (it’s on the label):


Are you familiar with looking at the HTML code? (with Chrome, try F12 and then right click and select Inspect)

this is an image which is inspect on mandatory and it’s on the label

@prashant.singh3 You have two different ways of showing mandatory, so you will need two different phrases. You can have your own names for the elements, but this will show you what I think. You can also add a FAILUREHANDLING option to the verifyMatch method if you want.

For QC Remarks, you could try:
WebUI.verifyMatch(WebUI.getAttribute(findTestObject(“mypage/span_QCRemark”), ‘class’), ‘icon-errorMandatoryMessageIconClass’, false)

what the above does is test the class attribute of the span_QCRemark element for the icon-errorMandatoryMessageIconClass phrase.

I would use the following XPath for the span_QCRemark element:

For the Decision label, you can use:
WebUI.verifyMatch(WebUI.getAttribute(findTestObject(“mypage/label_Decision”), ‘class’), “select-label control-label labelStyle mandatoryLabel”, false)

I would use the following XPath for the Decision label:

Just a note that if you copy and paste, you will have to check all the single and double quotes are not “smart” quotes–have a curve or curl to them. KS does not want “smart” quotes.

Another test you can do is to try to move off the page without entering data into the mandatory fields. Can you save, or click next, on the page without any error messages about filling in the mandatory fields? If you get an error message, is it (are they) the expected ones? For this, I use:“mypage/a_Save”)

WebUI.verifyTextPresent(“Vendor Name is a required field.”, false)

This depends on whether an error message is displayed, or a colour change highlights the element, or other indicator.

I tried this method but this is showing an error

Thank you, Now it is working fine. :grinning: