Skip to main content

ecommerce Scenario 5 — Compare Two Product Prices

Written by RTILA X Engineering Team

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

What You'll Learn

Scrape order history after login

Real-World Use Case

Generating personalised purchase reports

LIVE DEMO

Product 123

$149.99

Product 456

$129.99

Cheaper product: Product 456 at $129.99

EXPECTED OUTPUT

RTILA X PROJECT JSON

    {
  "name": "Compare_Two_Product_Prices",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/ecommerce/5"
    ]
  },
  "datasets": {
    "comparison_result": {
      "item_selector": "css=.comparison-result",
      "properties": [
        {
          "name": "message",
          "type": "text",
          "selector": "css=p"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.product-a .product-price",
        "iframe": "",
        "timeout": 30000
      }
    },
    {
      "command": "get_text",
      "params": {
        "selector": "css=.product-a .product-price",
        "output_variable": "price_a"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.product-b .product-price",
        "iframe": "",
        "timeout": 30000
      }
    },
    {
      "command": "get_text",
      "params": {
        "selector": "css=.product-b .product-price",
        "output_variable": "price_b"
      }
    },
    {
      "command": "if",
      "params": {
        "condition": {
          "type": "script",
          "expression": "${price_a} < ${price_b}"
        },
        "then": [
          {
            "command": "set_variable",
            "params": {
              "name": "cheaper",
              "value": "Product 123 at ${price_a}"
            }
          }
        ],
        "else": [
          {
            "command": "set_variable",
            "params": {
              "name": "cheaper",
              "value": "Product 456 at ${price_b}"
            }
          }
        ]
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "comparison_result"
      }
    }
  ]
}
  

Price comparison uses get_text to read values and an if condition to select the cheaper product.

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?