|
| 1 | +--- |
| 2 | +title: "Clicking Actions" |
| 3 | +description: "Learn how to use natural language commands for clicking elements with Auto-Browse" |
| 4 | +--- |
| 5 | + |
| 6 | +# Clicking Actions |
| 7 | + |
| 8 | +Auto-Browse provides an intuitive way to click elements using natural language commands. This guide covers various clicking scenarios and best practices. |
| 9 | + |
| 10 | +## Basic Clicking |
| 11 | + |
| 12 | +Click elements using natural language descriptions: |
| 13 | + |
| 14 | +```typescript |
| 15 | +// Click a button by its text |
| 16 | +await auto("click the Submit button"); |
| 17 | + |
| 18 | +// Click a link by its text |
| 19 | +await auto("click the Learn More link"); |
| 20 | + |
| 21 | +// Click an element by its role and name |
| 22 | +await auto('click the button labeled "Next"'); |
| 23 | +``` |
| 24 | + |
| 25 | +## Element Types |
| 26 | + |
| 27 | +Auto-Browse supports clicking various types of elements: |
| 28 | + |
| 29 | +### Buttons |
| 30 | + |
| 31 | +```typescript |
| 32 | +// Standard buttons |
| 33 | +await auto("click the Save button"); |
| 34 | +await auto("click Submit"); |
| 35 | + |
| 36 | +// Icon buttons with aria-labels |
| 37 | +await auto("click the close button"); |
| 38 | +await auto("click the menu icon"); |
| 39 | + |
| 40 | +// Button variants |
| 41 | +await auto("click the primary button"); |
| 42 | +await auto("click the cancel button"); |
| 43 | +``` |
| 44 | + |
| 45 | +### Links |
| 46 | + |
| 47 | +```typescript |
| 48 | +// Text links |
| 49 | +await auto("click the About link"); |
| 50 | +await auto("click Contact Us"); |
| 51 | + |
| 52 | +// Links with icons |
| 53 | +await auto("click the home link with icon"); |
| 54 | +await auto("click the external link"); |
| 55 | + |
| 56 | +// Navigation links |
| 57 | +await auto("click the next page link"); |
| 58 | +await auto("click the previous button"); |
| 59 | +``` |
| 60 | + |
| 61 | +### Form Elements |
| 62 | + |
| 63 | +```typescript |
| 64 | +// Checkboxes |
| 65 | +await auto('click the "Remember me" checkbox'); |
| 66 | +await auto("check the terms and conditions box"); |
| 67 | + |
| 68 | +// Radio buttons |
| 69 | +await auto('select the "Standard shipping" option'); |
| 70 | +await auto('click the "Express" radio button'); |
| 71 | + |
| 72 | +// Dropdowns |
| 73 | +await auto("click the country dropdown"); |
| 74 | +await auto("click to open the menu"); |
| 75 | +``` |
| 76 | + |
| 77 | +## Advanced Clicking |
| 78 | + |
| 79 | +### Contextual Clicking |
| 80 | + |
| 81 | +Specify element context for more precise targeting: |
| 82 | + |
| 83 | +```typescript |
| 84 | +// Click within a specific section |
| 85 | +await auto("click the Save button in the form"); |
| 86 | +await auto("click the Edit link in the user profile section"); |
| 87 | + |
| 88 | +// Click with multiple context hints |
| 89 | +await auto("click the Delete button in the first item of the list"); |
| 90 | +await auto("click the Download link in the latest notification"); |
| 91 | +``` |
| 92 | + |
| 93 | +### State-Based Clicking |
| 94 | + |
| 95 | +Handle elements based on their state: |
| 96 | + |
| 97 | +```typescript |
| 98 | +// Visibility checks |
| 99 | +await auto("click the button if it's visible"); |
| 100 | +await auto("click the notification after it appears"); |
| 101 | + |
| 102 | +// State-dependent clicking |
| 103 | +await auto("click the expand button if collapsed"); |
| 104 | +await auto("click the play button when enabled"); |
| 105 | +``` |
| 106 | + |
| 107 | +### Multiple Elements |
| 108 | + |
| 109 | +Handle scenarios with multiple similar elements: |
| 110 | + |
| 111 | +```typescript |
| 112 | +// Click specific instances |
| 113 | +await auto("click the first delete button"); |
| 114 | +await auto("click the last save button"); |
| 115 | + |
| 116 | +// Click by index |
| 117 | +await auto("click the 2nd item in the list"); |
| 118 | +await auto("click the 3rd tab"); |
| 119 | +``` |
| 120 | + |
| 121 | +## Best Practices |
| 122 | + |
| 123 | +### 1. Be Descriptive |
| 124 | + |
| 125 | +```typescript |
| 126 | +// Good - Clear and specific |
| 127 | +await auto("click the Submit button in the login form"); |
| 128 | + |
| 129 | +// Less Clear - Ambiguous |
| 130 | +await auto("click submit"); |
| 131 | +``` |
| 132 | + |
| 133 | +### 2. Use Element Context |
| 134 | + |
| 135 | +```typescript |
| 136 | +// Good - Provides context |
| 137 | +await auto("click the Edit button in the user profile card"); |
| 138 | + |
| 139 | +// Less Reliable - No context |
| 140 | +await auto("click edit"); |
| 141 | +``` |
| 142 | + |
| 143 | +### 3. Handle Dynamic Content |
| 144 | + |
| 145 | +```typescript |
| 146 | +// Good - Waits for element |
| 147 | +await auto("click the notification when it appears"); |
| 148 | + |
| 149 | +// Good - Verifies before clicking |
| 150 | +await auto("verify the modal is open then click Close"); |
| 151 | +``` |
| 152 | + |
| 153 | +## Common Patterns |
| 154 | + |
| 155 | +### 1. Navigation Flows |
| 156 | + |
| 157 | +```typescript |
| 158 | +async function navigationExample() { |
| 159 | + await auto("click the Products link in the main menu"); |
| 160 | + await auto("click the first category card"); |
| 161 | + await auto("click the Sort button"); |
| 162 | + await auto('click the option for "Price: Low to High"'); |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +### 2. Form Interactions |
| 167 | + |
| 168 | +```typescript |
| 169 | +async function formExample() { |
| 170 | + await auto("click to open the form"); |
| 171 | + await auto('click the "Personal" tab'); |
| 172 | + await auto("click the birthday date picker"); |
| 173 | + await auto("click to select today's date"); |
| 174 | + await auto("click Submit"); |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +### 3. Modal Interactions |
| 179 | + |
| 180 | +```typescript |
| 181 | +async function modalExample() { |
| 182 | + await auto("click to open settings"); |
| 183 | + await auto('click the "Advanced" tab in the modal'); |
| 184 | + await auto("click Save changes"); |
| 185 | + await auto("click to close the modal"); |
| 186 | +} |
| 187 | +``` |
| 188 | + |
| 189 | +## Error Handling |
| 190 | + |
| 191 | +Handle common clicking scenarios: |
| 192 | + |
| 193 | +```typescript |
| 194 | +try { |
| 195 | + await auto("click the Submit button"); |
| 196 | +} catch (error) { |
| 197 | + if (error.message.includes("not clickable")) { |
| 198 | + // Try scrolling into view first |
| 199 | + await auto("scroll until the Submit button is visible"); |
| 200 | + await auto("click the Submit button"); |
| 201 | + } |
| 202 | +} |
| 203 | +``` |
| 204 | + |
| 205 | +## Troubleshooting |
| 206 | + |
| 207 | +Common clicking issues and solutions: |
| 208 | + |
| 209 | +1. **Element Not Visible** |
| 210 | + |
| 211 | +```typescript |
| 212 | +// Scroll element into view first |
| 213 | +await auto("scroll until the button is visible"); |
| 214 | +await auto("click the button"); |
| 215 | +``` |
| 216 | + |
| 217 | +2. **Element Covered by Another Element** |
| 218 | + |
| 219 | +```typescript |
| 220 | +// Close overlays first |
| 221 | +await auto("close the cookie notice"); |
| 222 | +await auto("click the button"); |
| 223 | +``` |
| 224 | + |
| 225 | +3. **Dynamic Element Loading** |
| 226 | + |
| 227 | +```typescript |
| 228 | +// Wait for element to be ready |
| 229 | +await auto("wait for the Save button to appear"); |
| 230 | +await auto("click the Save button"); |
| 231 | +``` |
| 232 | + |
| 233 | +## Next Steps |
| 234 | + |
| 235 | +- Learn about [Typing Actions](/actions/typing) |
| 236 | +- Explore [Form Interactions](/actions/forms) |
| 237 | +- Check out [Navigation Actions](/actions/navigation) |
0 commit comments