Skip to main content

conditional-logic Scenario 3 — Check Stock Status and Extract Price

Written by RTILA X Engineering Team

Intermediate ~6 min
Prerequisites: conditional-logic/1 conditional-logic/2

What You'll Learn

Branch based on the presence of a captcha

Real-World Use Case

Deciding whether to solve or skip captcha

LIVE DEMO

Wireless Noise-Cancelling Headphones

SOLD OUT

Bluetooth Speaker

$149.99
EXPECTED OUTPUT

RTILA X PROJECT JSON

    {
  "name": "Stock_Status_And_Price",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/conditional-logic/3"
    ]
  },
  "datasets": {
    "stock_results": {
      "item_selector": "css=.product-detail",
      "properties": [
        {
          "name": "title",
          "type": "text",
          "selector": "css=.product-title"
        },
        {
          "name": "status",
          "type": "text",
          "selector": "css=.out-of-stock span, css=.price-section .price"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.product-detail"
      }
    },
    {
      "command": "if",
      "params": {
        "condition": {
          "type": "element_visible",
          "selector": "css=.out-of-stock"
        },
        "then": [
          {
            "command": "set_variable",
            "params": {
              "name": "stock_status",
              "value": "SOLD OUT"
            }
          }
        ],
        "else": [
          {
            "command": "get_text",
            "params": {
              "selector": "css=.price",
              "output_variable": "stock_status"
            }
          }
        ]
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "stock_results"
      }
    }
  ]
}
  

The set_variable and get_text commands allow conditional values to be captured. Here, if an out-of-stock element exists, the status is set to SOLD OUT; otherwise the price is read into the same variable.

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?