Skip to content

Commit 568428d

Browse files
committed
some tests cases and plumbing
1 parent 0a4bea2 commit 568428d

File tree

5 files changed

+750
-38
lines changed

5 files changed

+750
-38
lines changed

stagehand/a11y/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ async def get_accessibility_tree(
328328
const pathIndex = hasSameTypeSiblings ? `[${index}]` : "";
329329
parts.unshift(`${tagName}${pathIndex}`);
330330
}
331-
331+
332332
current = current.parentElement;
333333
}
334334

stagehand/utils.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def draw_observe_overlay(page, elements: list[dict]):
125125
(elements) => {
126126
// First remove any existing overlays
127127
document.querySelectorAll('.stagehand-observe-overlay').forEach(el => el.remove());
128-
128+
129129
// Create container for overlays
130130
const container = document.createElement('div');
131131
container.style.position = 'fixed';
@@ -137,26 +137,26 @@ async def draw_observe_overlay(page, elements: list[dict]):
137137
container.style.zIndex = '10000';
138138
container.className = 'stagehand-observe-overlay';
139139
document.body.appendChild(container);
140-
140+
141141
// Process each element
142142
elements.forEach((element, index) => {
143143
try {
144144
// Parse the selector
145145
let selector = element.selector;
146146
if (selector.startsWith('xpath=')) {
147147
selector = selector.substring(6);
148-
148+
149149
// Evaluate the XPath to get the element
150150
const result = document.evaluate(
151-
selector, document, null,
151+
selector, document, null,
152152
XPathResult.FIRST_ORDERED_NODE_TYPE, null
153153
);
154-
154+
155155
if (result.singleNodeValue) {
156156
// Get the element's position
157157
const el = result.singleNodeValue;
158158
const rect = el.getBoundingClientRect();
159-
159+
160160
// Create the overlay
161161
const overlay = document.createElement('div');
162162
overlay.style.position = 'absolute';
@@ -168,7 +168,7 @@ async def draw_observe_overlay(page, elements: list[dict]):
168168
overlay.style.backgroundColor = 'rgba(255, 0, 0, 0.1)';
169169
overlay.style.boxSizing = 'border-box';
170170
overlay.style.pointerEvents = 'none';
171-
171+
172172
// Add element ID
173173
const label = document.createElement('div');
174174
label.textContent = index + 1;
@@ -180,7 +180,7 @@ async def draw_observe_overlay(page, elements: list[dict]):
180180
label.style.padding = '2px 5px';
181181
label.style.borderRadius = '3px';
182182
label.style.fontSize = '12px';
183-
183+
184184
overlay.appendChild(label);
185185
container.appendChild(overlay);
186186
}
@@ -189,7 +189,7 @@ async def draw_observe_overlay(page, elements: list[dict]):
189189
const el = document.querySelector(selector);
190190
if (el) {
191191
const rect = el.getBoundingClientRect();
192-
192+
193193
// Create the overlay (same as above)
194194
const overlay = document.createElement('div');
195195
overlay.style.position = 'absolute';
@@ -201,7 +201,7 @@ async def draw_observe_overlay(page, elements: list[dict]):
201201
overlay.style.backgroundColor = 'rgba(255, 0, 0, 0.1)';
202202
overlay.style.boxSizing = 'border-box';
203203
overlay.style.pointerEvents = 'none';
204-
204+
205205
// Add element ID
206206
const label = document.createElement('div');
207207
label.textContent = index + 1;
@@ -213,7 +213,7 @@ async def draw_observe_overlay(page, elements: list[dict]):
213213
label.style.padding = '2px 5px';
214214
label.style.borderRadius = '3px';
215215
label.style.fontSize = '12px';
216-
216+
217217
overlay.appendChild(label);
218218
container.appendChild(overlay);
219219
}
@@ -222,7 +222,7 @@ async def draw_observe_overlay(page, elements: list[dict]):
222222
console.error(`Error drawing overlay for element ${index}:`, error);
223223
}
224224
});
225-
225+
226226
// Auto-remove after 5 seconds
227227
setTimeout(() => {
228228
document.querySelectorAll('.stagehand-observe-overlay').forEach(el => el.remove());

0 commit comments

Comments
 (0)