conditional-logic Scenario 7 — Search Fallback with Alternate Keyword
Written by RTILA X Engineering Team
Advanced ~10 min
Prerequisites: conditional-logic/3 conditional-logic/4 conditional-logic/5
What You'll Learn
Implement search fallback with alternate inputs
Real-World Use Case
Retrying with different search terms
LIVE DEMO
EXPECTED OUTPUT
RTILA X PROJECT JSON
{
"name": "Search_Fallback_Alternate_Keyword",
"settings": {
"urls": [
"https://learn.rtila.com/scenarios/conditional-logic/7"
]
},
"datasets": {
"fallback_results": {
"item_selector": "css=.search-result-item",
"properties": [
{
"name": "title",
"type": "text",
"selector": "css=.result-title"
}
]
}
},
"commands": [
{
"command": "wait_for_selector",
"params": {
"selector": "css=#fallback-search"
}
},
{
"command": "fill",
"params": {
"selector": "css=#fallback-search",
"value": "phones"
}
},
{
"command": "wait_for_selector",
"params": {
"selector": "css=#fallback-search-btn"
}
},
{
"command": "click",
"params": {
"selector": "css=#fallback-search-btn"
}
},
{
"command": "wait",
"params": {
"timeout": 1000
}
},
{
"command": "if",
"params": {
"condition": {
"type": "script",
"expression": "document.querySelector('.result-count').textContent.includes('0 results')"
},
"then": [
{
"command": "fill",
"params": {
"selector": "css=#fallback-search",
"value": "smartphones"
}
},
{
"command": "wait_for_selector",
"params": {
"selector": "css=#fallback-search-btn"
}
},
{
"command": "click",
"params": {
"selector": "css=#fallback-search-btn"
}
},
{
"command": "wait",
"params": {
"timeout": 1000
}
}
],
"else": []
}
},
{
"command": "wait_for_selector",
"params": {
"selector": "css=.search-result-item"
}
},
{
"command": "extract_data",
"params": {
"dataset": "fallback_results"
}
}
]
}
Search fallback patterns leverage a script condition to read the result count. If zero results are detected, the automation replaces the query with a successful fallback keyword, performs the new search, and extracts the returned items.
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!