Automate login to a website with otp

Hi, i am new to UiPath and would like to automate the following workflow:

  1. Login to a Website – Authenticate using a username/email and password.
  2. Retrieve OTP from Outlook 365 – Extract the OTP from an email and enter it on the website.

Here is what i did:

  1. Login to the Website**
  • Use the Open Browser activity to navigate to the website.
  • Use Type Into [activities]to enter the username/email and password.
  • Click the Login button using the Click activity.
  1. Retrieve OTP from Outlook365**
  • Use the Wait for Email received & resume Outlook 365 activity to retrieve the email.
  • Apply a filter to extract the latest OTP email
  • Use Extract Text to extract the OTP from the email body.

I have stuck here. How to i get back to the login page? I tried Open browser but it open the 1st page which login with username and password but not the previous page that require OTP input.

I am using web studio.

Hi @mcc.it

Open the browser and navigate to the login page, then enter the username and password, and click the login button. Store the browser in a variable before retrieving the OTP from Outlook 365. After extracting the OTP from the email, use the same browser session to return to the OTP input page, enter the OTP, and proceed with the automation.

If you found helpful, feel free to tick as a solution.
Happy Automation

Hi,

Can you brief more on this? How do we store the browser in a varieble?

Thanks

The wait for email received and resume activity is a very very bad idea to use in this context.

This will cause your process to suspend, this means that the job basically stops and is returned to the Orchestrator, this can and will cause numerous problems, the first is that the job might resume on a different account or machine (if you setup allows such things), whilst this can be mitigated, the next problem cannot and that is that if there is another job pending that the other job will start whilst you have the wait action pending. As a result in might be 30 minutes later that your job resumes since another job runs first and then not only might your OTP be expired but your browser might have been completely closed by the other process.

To do this you need to not break up your process in this way.

I’d actually recommend finding a different way to authenticate, if possible switch the MFA to TOTP as the robot would then be able to generate the token required to get into the next step, otherwise, you need to wait for the email but likely with a loop so your process continues to run.

Not possible, the Wait activity will suspend the process. This might not even be possible if you have a browser variable in scope as I can imagine it won’t be serializable, even if it is, when the job resumes the variable will hold a junk value thats not properly connected to the browser anymore.

1 Like

Hi Jon,

I have no option to change the authentication method as that was a 3rd party website. You are correct, the wait for email received was always timeout and i cant refer back to the otp input pages. What would you suggest me?

i would say create a small sequence to get your otp from email using difference browser than your main browser.
Then get your OTP and close the browser instance.
Then go back to your main browser where login screen is still active and enter otp there.

I hope this will works

@mcc.it
A crude solution will be

  1. Login to your website using the creds.
  2. Assign a timestamp var.
  3. Use a while loop where you will wait for the mail to arrive and then extract your OTP. Assign a bool var as True
  4. Break the loop after a default time or if you have extracted the OTP.
  5. Enter the OTP on your webpage.