Random field in the application

I have 3 Edits that appear in a random way, example: Date of birth, city or Country, how do I in the “katalon” to select the field that will appear? Help me please!

How are your fields identified? Isn’t it unique for every field?

I have a data validation screen, where one of the fields I mentioned appears once in a random way, and I do not know which field will appear … Since I have already captured these objects for testing, I just do not know how to perform the IF no katalon!

I am not sure if I got it correctly, but is this what you need?

if(WebUI.waitForElementVisible(testObject1, 1, FailureHandling.OPTIONAL)) {
	// do stuff for test object 1
} else if(WebUI.waitForElementVisible(testObject2, 1, FailureHandling.OPTIONAL)) {
	// do stuff for test object 2
} else if(WebUI.waitForElementVisible(testObject3, 1, FailureHandling.OPTIONAL)) {
	// do stuff for test object 3
} else {
	KeywordUtil.markWarning("None of test objects are present.")
}
1 Like

Only one of these appears at once on the screen at random according to the image …

I think so, this must be it, but I need to perform data insertion in the field! Thank’s for help!
I’ll test by the example you sent.

That would be it, I tried to use as an example what I sent, but it did not work, because I need to perform insert data

Yes, you need to put actual code into if blocks, e.g. if this field is visible, then set this text to it.

1 Like

Here’s how I did it in my code:

if (Mobile.verifyElementExist(findTestObject(‘TrocarSenhaInApp/android.widget.EditText0 - RG’), 1, FailureHandling.OPTIONAL)) {
Mobile.setText(findTestObject(‘TrocarSenhaInApp/android.widget.EditText0 - RG’), ‘2276708’, 30,FailureHandling.OPTIONAL)

} else if (Mobile.verifyElementExist(findTestObject(‘TrocarSenhaInApp/android.widget.EditText0 - Data de nascimento’), 1, FailureHandling.OPTIONAL)) {
Mobile.setText(findTestObject(‘TrocarSenhaInApp/android.widget.EditText0 - Data de nascimento’), ‘12051959’, 30,FailureHandling.OPTIONAL)

} else if (Mobile.verifyElementExist(findTestObject(‘TrocarSenhaInApp/android.widget.EditText0 - CPF’), 1, FailureHandling.OPTIONAL)) {
Mobile.setText(findTestObject(‘TrocarSenhaInApp/android.widget.EditText0 - CPF’), ‘10936912200’, 30,FailureHandling.OPTIONAL)

}

Mobile.tap(findTestObject(‘TrocarSenhaInApp/android.widget.Button2 - CONFIRMAR’), 30)

It seems correct - doesn’t it work now?

1 Like

Unfortunately it has not worked yet, always stays on the first IF “RG”, Thanks for the attention and help!

Regardless of the field that appears, it always enters with the value of the “RG”

Ok, let’s try this:

println Mobile.verifyElementExist(findTestObject('TrocarSenhaInApp/android.widget.EditText0 - RG'), 1, FailureHandling.OPTIONAL)
println Mobile.verifyElementExist(findTestObject('TrocarSenhaInApp/android.widget.EditText0 - Data de nascimento'), 1, FailureHandling.OPTIONAL)
println Mobile.verifyElementExist(findTestObject('TrocarSenhaInApp/android.widget.EditText0 - CPF'), 1, FailureHandling.OPTIONAL)

And check console if only visible element prints true.

View result console

I believe you printed the three fields, If you can see in the log that I send

result console.txt (70.7 KB)

Hmm, the outcome should be true/false as verifyElementExist returns boolean value.

Check out the above console log I sent again…

I see it. All 3 fields are present according to the log. Is it possible?

No, only one field appears randomly on the screen at a time.