Skip to main content

conditional-logic Scenario 2 — Accept Cookie Consent Before Scraping

Written by RTILA X Engineering Team

Beginner ~4 min

What You'll Learn

Accept cookie consent banners conditionally

Real-World Use Case

Complying with GDPR cookie prompts

LIVE DEMO

Welcome to Our Site

NameRoleDepartment
Alice SmithEngineerPlatform
Bob JonesDesignerProduct
Carol WhiteManagerOperations
Dan GreenAnalystData
Eve BlackDeveloperMobile
EXPECTED OUTPUT

RTILA X PROJECT JSON

    {
  "name": "Accept_Cookie_Consent",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/conditional-logic/2"
    ]
  },
  "datasets": {
    "content_rows": {
      "item_selector": "css=.content-table tbody tr",
      "properties": [
        {
          "name": "name",
          "type": "text",
          "selector": "css=td:nth-child(1)"
        },
        {
          "name": "role",
          "type": "text",
          "selector": "css=td:nth-child(2)"
        },
        {
          "name": "department",
          "type": "text",
          "selector": "css=td:nth-child(3)"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=#cookie-consent"
      }
    },
    {
      "command": "if",
      "params": {
        "condition": {
          "type": "element_visible",
          "selector": "css=#cookie-consent"
        },
        "then": [
          {
            "command": "click",
            "params": {
              "selector": "css=#accept-cookies"
            }
          },
          {
            "command": "wait",
            "params": {
              "timeout": 1000
            }
          }
        ],
        "else": []
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.content-table"
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "content_rows"
      }
    }
  ]
}
  

Cookie banners often block page interactions. This scenario uses an if guard to check whether the banner exists, click the accept button, and then extract the data from the now-visible table.

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?