Skip to main content

authentication Scenario 7 — Login with URL-Based 2FA Detection

Written by RTILA X Engineering Team

Advanced ~10 min
Prerequisites: authentication/4 authentication/5 authentication/6

What You'll Learn

Detect two-factor steps using script-based URL checks

Real-World Use Case

Dealing with non-standard 2FA implementations

LIVE DEMO

URL-Based 2FA Detection

The same two-factor demo simulates URL-triggered detection when the browser URL includes the /2fa marker.

EXPECTED OUTPUT

Verified Account Data

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

RTILA X Automation Project

url-based-twofa-detection.json
    {
  "name": "Login_With_URL_Based_2FA_Detection",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/authentication/7#/2fa"
    ]
  },
  "datasets": {
    "account_data": {
      "item_selector": "css=.account-data 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/7#/2fa"
      }
    },
    {
      "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_load_state",
      "params": {
        "state": "networkidle"
      }
    },
    {
      "command": "if",
      "params": {
        "condition": {
          "type": "script",
          "expression": "window.location.href.includes('/2fa')"
        },
        "then": [
          {
            "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

A script-based if condition can evaluate browser state dynamically. Here the check looks for a marker in window.location.href to decide whether to present the second-factor prompt.

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 2 RTILA X commands and is referenced in 2 learning articles.

Continue Learning

Was this helpful?