Skip to main content

variables Scenario 1 — Loop Over Keyword List Variable

Written by RTILA X Engineering Team

Beginner ~4 min

What You'll Learn

Set and use variables in URLs

Real-World Use Case

Parameterising search queries

LIVE DEMO

Laptop A

13-inch ultrabook

Laptop B

15-inch workstation

Laptop C

14-inch gaming laptop

EXPECTED OUTPUT

RTILA X PROJECT JSON

    {
  "name": "Loop_Over_Keyword_List",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/variables/1"
    ],
    "variables": [
      {
        "name": "keywords",
        "is_list": true,
        "value": [
          "laptop",
          "phone",
          "tablet"
        ]
      }
    ]
  },
  "datasets": {
    "keyword_results": {
      "item_selector": "css=.keyword-result",
      "properties": [
        {
          "name": "keyword",
          "type": "text",
          "selector": "css=.kw-title"
        },
        {
          "name": "title",
          "type": "text",
          "selector": "css=.kw-title"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "for_each",
      "params": {
        "source_type": "variable",
        "variable": "keywords",
        "as": "keyword",
        "do": [
          {
            "command": "goto",
            "params": {
              "url": "https://learn.rtila.com/scenarios/variables/1?q=${keyword}"
            }
          },
          {
            "command": "wait_for_selector",
            "params": {
              "selector": "css=.keyword-result",
              "iframe": "",
              "timeout": 30000
            }
          },
          {
            "command": "extract_data",
            "params": {
              "dataset": "keyword_results"
            }
          }
        ]
      }
    }
  ]
}
  

The for_each command iterates over a list variable. Each keyword becomes the value of ${keyword} inside the loop body and is appended to the visited URL.

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

Continue Learning

Was this helpful?