Skip to main content

variables Scenario 5 — Search with Global Variable Value

Written by RTILA X Engineering Team

Advanced ~10 min
Prerequisites: variables/3 variables/4

What You'll Learn

Combine variables with complex control flow

Real-World Use Case

Implementing stateful scraping logic

LIVE DEMO

EXPECTED OUTPUT

RTILA X PROJECT JSON

    {
  "name": "Global_Variable_Search",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/variables/5"
    ],
    "variables": [
      {
        "name": "search_term",
        "is_list": false,
        "value": "wireless headphones"
      }
    ]
  },
  "datasets": {
    "global_search_results": {
      "item_selector": "css=.global-result",
      "properties": [
        {
          "name": "title",
          "type": "text",
          "selector": "css=.global-title"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=#global-search-input"
      }
    },
    {
      "command": "fill",
      "params": {
        "selector": "css=#global-search-input",
        "value": "${search_term}"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=#global-search-btn"
      }
    },
    {
      "command": "click",
      "params": {
        "selector": "css=#global-search-btn"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.global-results"
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "global_search_results"
      }
    }
  ]
}
  

Global variables can be referenced directly in command parameters. Here, the fill command uses ${search_term} to inject the configured search phrase.

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?