Skip to main content

basic-navigation Scenario 12 — Extract All data-* Attributes

Written by RTILA X Engineering Team

Advanced ~10 min
Prerequisites: basic-navigation/9 basic-navigation/10

What You'll Learn

Collect multiple data-* attributes from repeated elements

Real-World Use Case

Harvesting embedded product data from a data layer

LIVE DEMO

Data Attributes

Five cards with product identifiers stored in data attributes.

Product P001

Electronics

$29.99

Product P002

Clothing

$49.00

Product P003

Books

$19.95

Product P004

Home & Garden

$89.50

Product P005

Sports

$59.99

EXPECTED OUTPUT

Extracted data-* Attributes

product_id category price
P001 Electronics 29.99
P002 Clothing 49.00
P003 Books 19.95
P004 Home & Garden 89.50
P005 Sports 59.99
RTILA X PROJECT JSON

RTILA X Automation Project

extract-data-attributes.json
    {
  "name": "Extract_All_data_Attributes",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/basic-navigation/12"
    ]
  },
  "datasets": {
    "data_items": {
      "item_selector": "css=div.data-item",
      "properties": [
        {
          "name": "product_id",
          "type": "attribute",
          "selector": "css=self",
          "attribute": "data-product-id"
        },
        {
          "name": "category",
          "type": "attribute",
          "selector": "css=self",
          "attribute": "data-category"
        },
        {
          "name": "price",
          "type": "attribute",
          "selector": "css=self",
          "attribute": "data-price"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "goto",
      "params": {
        "url": "https://learn.rtila.com/scenarios/basic-navigation/12"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=div.data-item"
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "data_items"
      }
    }
  ]
}
  

RTILA X Concepts

Any HTML attribute can be extracted using the attribute property type and the attribute name. Using css=self guarantees each property reads from the current item.

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?