Using If statements for Login

Hi, I’m conducting UAT test cases on a new system that involves logging in using a Username, Password and 3 random digits from a predefined 6 digit PIN. I’m using Katalon Recorder to create some automation testing but I can’t figure out how to configure it to work with the random PIN digits, for example, I need the test case to look for PIN#1 and enter the corresponding digit if present, but skip it if not present, and then look for PIN#2 and so on. I’ve tried to set up ‘If’ commands, but i haven’t got it to work so far. Can anyone guide me on how this can be done please? Thanks

@Piotr can you assist on this?

Hi i can try to hep :slight_smile:
Correct me if i’m wrong: You have your 6 digit password like: 795432 and webpage tells you to write in input digits from for example first, third and fifth place which is 753
If that’s the case you need to use JS to prepare this 3 digit combitantion.
If message on the page is like “Please write 1, 3 and 5 digit of your password” try to use regex to extract only digit and then use this digits as index to your password to get corresponding digits save it in variable and then write it in input.

If You have multiples PINs you can of course use if command.
I think it;s might be easier to not use if command in Katalon itself but just right everything in JS and run it on login page.

Can You provide more info about page? Screen maybe? HTML code?

Hi Piotr,

Thanks for your reply. Unfortunately I’m not familiar with writing code in JavaScript. Katalon Recorder is the only tool I’m using for Automation. Apologies, I’m a real novice at this whole thing.

In terms of the login page, it’s a fairly simple layout just with Username field, Password field and then 3 separate boxes for the random PIN digits. The PIN boxes have ids like id=PIN-1, PIN-2 for example. If it’s possible to use Katalon Recorder to enter the required digits, that would be preferable for me. We use a generic PIN code for all accounts 010101. So basically, I need Katalon to check if PIN-1 box is present, type 0, if not present, check if PIN-2 is present and type 1, and so on. Is that possible?

Thanks for your help so far :slight_smile:

It is possible. You have to do excatly what you describe :slight_smile:
So first you have to check if element is presented on page, search for command like verifyElementPresent or assertElementPresent (I never use them so can’t help specifically with them). This commands should return true or false depending if given element is on page. Then you use “if” command to check this true/false statement and if true type one of digit in corresponding boxes. You have to copy all of this 6 times of 6 digit password.
So it’s should be something like this - consider password is 123456 (I write it from my head):

assertElementPresent | id=PIN-1 | isPin1OnPage
if | isPin1OnPage
type | id=Box1 | 1
assertElementPresent | id=PIN-2 | isPin2OnPage
if | isPin2OnPage
type | id=Box2 | 2
and so on and so forth.

But i suggest You to try write it in JS. It’s shouldn’t be hard and it will be much much faster. Katalon solution takes: {speedOfExecution} * 3(commands for each password character) * 6(character password)
So it’s 18 * speed of execution in Katalon (slider) So if You set it to something like 1s it will execute for 18s and JS solution will be instant.

In JS (like previuos - I write from head without checking it):

if (document.getElementbyId(‘PIN-1’)) {document.getElementById(‘Box1’).value = ‘1’}
if (document.getElementbyId(‘PIN-2’)) {document.getElementById(‘Box2’).value = ‘2’}

and so on. And when You get more familiar with JS you can change it to loop later on.

Hi Piotr,

Thanks for your reply. I tried to input the commands in Katalon as listed above, but it’s giving errors for me. In the log, one error is “ReferenceError : IsPin1OnPage is not defined.” Is there something I’m missing that could be causing that error?


Oh, my bad, sorry.
When You use variable i.e. IsPin1OnPage You have to use format ${IsPin1OnPage }
When You save something to it just use it name but if You use in “if” command or something like that when You want actual value of it You have to use ${variableName} format

Hi Piotr,

Unfortunately, this is still not working for me in katalon. My commands are as follows:

verifyElementPresent | id=Pin-1 | isPin1OnPage
if | ${isPin1OnPage}
setText | id=Pin-1 | 0
verifyElementPresent | id=Pin-2 | isPin2OnPage
if | isPin2OnPage
setText | id=Pin-2 | 1

and so on.
I’m using VerifyElementpresent as Assert stops the test case if false.
The log is telling me it’s getting a syntax error: Unexpected token ‘{’

Am I doing something wrong from your instructions? I appreciate the help so far.


verifyElementPresent does not save anything to variable. It’s just pass or fail.
To check it use this command and at target use //html and run it. It will go green.
But if You put something like //html/div[1000] You probably don’t have such element so when You run it it will be red.
Instead of verifyElementPresent use storeElementPresent run it and check “Variables” tab in Katalon. You’ll have boolean varibles in it with true or false depending on the elements.
Rest of your code look ok to me.