# Robust Alert Creation Process ## Key Principles for Reliability ### 1. **Always Fresh Snapshots** - Get snapshot BEFORE every action - Never reuse refs from previous snapshots - Elements change refs on every page load ### 2. **Dynamic Element Finding** - Find elements by `name` attribute, not cached refs - Use grep to search snapshot files for element names - Extract ref from current snapshot only ### 3. **Random Variance (Human-like)** - Delays: 0.5-2 seconds between actions - Typing: 30% slow, 70% fast - Wait times: 1-3 seconds after clicks ### 4. **Error Handling** - Retry failed actions with exponential backoff - Get fresh snapshot on error - Re-find elements on retry ## Step-by-Step Process (Per Query) ``` 1. Navigate → https://www.google.com/alerts 2. Wait 1-2s (random) 3. Get snapshot 4. Find "Create an alert about..." → extract ref 5. Click textbox 6. Wait 0.5-1s (random) 7. Type query (slowly=random 30% chance) 8. Wait 1-2s (random) 9. Get snapshot 10. Find "Show option" → extract ref 11. Click "Show option" 12. Wait 1-2s (random) 13. Get snapshot 14. Find delivery dropdown ("knappcolin04@gmail.com") → extract ref 15. Click dropdown 16. Wait 1-2s (random) 17. Get snapshot 18. Find "RSS feed" option → extract ref 19. Click "RSS feed" 20. Wait 0.5-1s (random) 21. Get snapshot 22. Find "Create Alert" → extract ref 23. Click "Create Alert" 24. Wait 2-4s (random) 25. Navigate back to alerts page 26. Repeat for next query ``` ## Implementation Pattern ```python # Pseudo-code pattern: for query in queries: # Navigate browser_navigate("https://www.google.com/alerts") time.sleep(random_delay(1, 2)) # Get fresh snapshot snapshot = browser_snapshot() # Find element dynamically ref = find_element_by_name(snapshot, "Create an alert about...") # Click with delay browser_click(ref) time.sleep(random_delay(0.5, 1)) # Type with variance slowly = should_type_slowly() # 30% chance browser_type(ref, query, slowly=slowly) time.sleep(random_delay(1, 2)) # Continue pattern... ``` ## Why This Works 1. **Fresh refs** = No stale element errors 2. **Random timing** = Human-like, avoids detection 3. **Dynamic finding** = Works even when page structure changes 4. **Retries** = Handles transient errors 5. **Proper waits** = Elements ready before interaction