Skip to main content

authentication Scenario 4 — Login with 2FA Prompt

Written by RTILA X Engineering Team

Intermediate ~6 min
Prerequisites: basic-navigation/1 forms/1

What You'll Learn

Handle two-factor authentication prompts

Real-World Use Case

Automating sites that require OTP verification

LIVE DEMO

Two-Factor Login

A two-step login form that requires a simulated six-digit one-time code.

EXPECTED OUTPUT

Account Data After 2FA

label value
Email user@test.com
Role Admin
2FA Status Enabled
RTILA X PROJECT JSON

RTILA X Automation Project

login-two-factor-prompt.json
    {
  "name": "Login_With_2FA_Prompt",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/authentication/4"
    ]
  },
  "datasets": {
    "account_data": {
      "item_selector": "css=table tr",
      "properties": [
        {
          "name": "label",
          "type": "text",
          "selector": "css=td:first-child"
        },
        {
          "name": "value",
          "type": "text",
          "selector": "css=td:last-child"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "goto",
      "params": {
        "url": "https://learn.rtila.com/scenarios/authentication/4"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=#login-form-step1"
      }
    },
    {
      "command": "fill",
      "params": {
        "selector": "css=#email-2fa",
        "value": "user@test.com"
      }
    },
    {
      "command": "fill",
      "params": {
        "selector": "css=#password-2fa",
        "value": "secret"
      }
    },
    {
      "command": "click",
      "params": {
        "selector": "css=#submit-credentials"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=#two-factor-step"
      }
    },
    {
      "command": "prompt_user",
      "params": {
        "reason": "Enter the 2FA code sent to your device",
        "fields": [
          {
            "name": "otp_code",
            "type": "text"
          }
        ],
        "output_variable": "otp_code"
      }
    },
    {
      "command": "fill",
      "params": {
        "selector": "css=#otp-input",
        "value": "${otp_code}"
      }
    },
    {
      "command": "click",
      "params": {
        "selector": "css=#verify-otp"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.account-data"
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "account_data"
      }
    }
  ]
}
  

RTILA X Concepts

prompt_user pauses automation and asks the operator for input. The returned variable is then used with fill and command variable syntax ${variable} to complete the second factor.

Did you complete this scenario?

Ready to run this automation?

Copy the project JSON above, open RTILA X, create a new project, and paste it.

This scenario covers 3 RTILA X commands and is referenced in 2 learning articles.

Continue Learning

Was this helpful?