How to continue if an exception occurs during execution of flow

Hi All,

I was learning the Try Catch concept by practicing the below scenario.

Scenario: I have an excel file with two columns - “Username” & “Password”
1st row → invalid username invalid password
2nd row–> valid username valid password

Below are the steps that I am performing in this workflow

  1. Open the browser and open www.gmail.com
  2. Click “Use another account” option on gmail login page
    → After this step, system will display the “Email or phone” text field with “Next” button
  3. Enter value in the “Email or phone” text field
  4. Click “Next” button
    —> After this step, system will display the “Enter your password” field with “Next” button
  5. Enter value in “Password” field
  6. Click “Next” button
    —> After this step, user will be logged in successfully.
  7. Click Logout button.

So, I have designed the bot using For Each activity and used Try Catch inside it.
For the first iteration, I got an exception after step 4 (because system won’t find the gmail account with invalid username) and flow went into the Catch section and notified the user about “invalid account” (Note: this is customised message just to inform user about invalid login credentials).

What I want to achieve here is after getting an exception, system should remove the invalid value from “Email or phone” text field, enter a valid value from 2nd row in the excel and follow step 4 to 7.

Actual Result: Workflow doesn’t move onto the 2nd row in the excel. And after sometime again throws a exception for not finding the correct UIelement.

Can someone please guide me OR suggest a correction in my workflow? Attaching my workflow file along with this query.

Gmail_Login_Using_TryCatch.xaml (27.0 KB)

@DeepakPhalak -
Keep one Try/Catch block inside For each body block (surrounded with Attach-window) and catch the exception and do the continue/iteration to the next row.

1 Like

Hi @DeepakPhalak

Try to do the following:

  • Use a For Each block to loop through the excel rows (i`m assuming that you retrieve them using excel activities)
  • For Each interaction use a Try/Catch block
    ** 2.1Inside the Try block you should insert the activities to try the login, which are steps 2,3,4,5 and 6 in your example. After step 6 you should somehow test if you were able to sucessfully login, you could use element exist activity and get a element that only exists when you are logged. Use an IF statement passing the boolean variable. If the element exist means that you logged in so u can use a break activity to stop the For Each loop. Otherwise, you didn`t logged in, so u could use “Navigate to” activity to go to gmail home page again and use a “Throw” activity (by doing that you will activate the catch block where you can display the “invalid account” message to the user or something like that.)

Remember that after you fail to login in the first time you need to go back in the login page where the elements of step 2 will be valid. This might be why u are getting error of not finding UiElement.

Hope this helps!

Happy coding! =)

2 Likes

In your learning, just be sure that using a Try Catch block is not the solution for all of your automation needs. For larger projects, the REFramework is a more reliable solution.