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
Stock Status and Price
Branch on the out-of-stock element to capture either the status or the price.
Wireless Noise-Cancelling Headphones
SOLD OUT
Bluetooth Speaker
$149.99
EXPECTED OUTPUT
Stock Results
| title | status |
|---|---|
| Wireless Noise-Cancelling Headphones | SOLD OUT |
| Bluetooth Speaker | $149.99 |
RTILA X PROJECT JSON
RTILA X Automation Project
stock-status-and-price.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=.product-detail > div:not([style*=\"display:none\"]) span"
},
{
"name": "sold_out_in_page",
"selector": "variable=sold_out_in_page"
}
]
}
},
"commands": [
{
"command": "if",
"params": {
"condition": {
"type": "element_visible",
"selector": "css=.out-of-stock"
},
"then": [
{
"command": "set_variable",
"params": {
"name": "sold_out_in_page",
"value": "Yes"
}
}
],
"else": []
}
},
{
"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?
Thank you for your feedback!