|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import {logger} from '../logger.js'; |
8 | | -import type {McpContext, TextSnapshotNode} from '../McpContext.js'; |
| 8 | +import type {McpContext} from '../McpContext.js'; |
9 | 9 | import {zod} from '../third_party/index.js'; |
10 | 10 | import type {ElementHandle} from '../third_party/index.js'; |
11 | 11 | import {parseKey} from '../utils/keyboard.js'; |
@@ -140,61 +140,19 @@ export const hover = defineTool({ |
140 | 140 | }, |
141 | 141 | }); |
142 | 142 |
|
143 | | -// The AXNode for an option doesn't contain its `value`. We set text content of the option as value. |
144 | | -// If the form is a combobox, we need to find the correct option by its text value. |
145 | | -// To do that, loop through the children while checking which child's text matches the requested value (requested value is actually the text content). |
146 | | -// When the correct option is found, use the element handle to get the real value. |
147 | | -async function selectOption( |
148 | | - handle: ElementHandle, |
149 | | - aXNode: TextSnapshotNode, |
150 | | - value: string, |
151 | | -) { |
152 | | - let optionFound = false; |
153 | | - for (const child of aXNode.children) { |
154 | | - if (child.role === 'option' && child.name === value && child.value) { |
155 | | - optionFound = true; |
156 | | - const childHandle = await child.elementHandle(); |
157 | | - if (childHandle) { |
158 | | - try { |
159 | | - const childValueHandle = await childHandle.getProperty('value'); |
160 | | - try { |
161 | | - const childValue = await childValueHandle.jsonValue(); |
162 | | - if (childValue) { |
163 | | - await handle.asLocator().fill(childValue.toString()); |
164 | | - } |
165 | | - } finally { |
166 | | - void childValueHandle.dispose(); |
167 | | - } |
168 | | - break; |
169 | | - } finally { |
170 | | - void childHandle.dispose(); |
171 | | - } |
172 | | - } |
173 | | - } |
174 | | - } |
175 | | - if (!optionFound) { |
176 | | - throw new Error(`Could not find option with text "${value}"`); |
177 | | - } |
178 | | -} |
179 | | - |
180 | 143 | async function fillFormElement( |
181 | 144 | uid: string, |
182 | 145 | value: string, |
183 | 146 | context: McpContext, |
184 | 147 | ) { |
185 | 148 | const handle = await context.getElementByUid(uid); |
186 | 149 | try { |
187 | | - const aXNode = context.getAXNodeByUid(uid); |
188 | | - if (aXNode && aXNode.role === 'combobox') { |
189 | | - await selectOption(handle, aXNode, value); |
190 | | - } else { |
191 | | - // Increase timeout for longer input values. |
192 | | - const timeoutPerChar = 10; // ms |
193 | | - const fillTimeout = |
194 | | - context.getSelectedPage().getDefaultTimeout() + |
195 | | - value.length * timeoutPerChar; |
196 | | - await handle.asLocator().setTimeout(fillTimeout).fill(value); |
197 | | - } |
| 150 | + // Increase timeout for longer input values. |
| 151 | + const timeoutPerChar = 10; // ms |
| 152 | + const fillTimeout = |
| 153 | + context.getSelectedPage().getDefaultTimeout() + |
| 154 | + value.length * timeoutPerChar; |
| 155 | + await handle.asLocator().setTimeout(fillTimeout).fill(value); |
198 | 156 | } catch (error) { |
199 | 157 | handleActionError(error, uid); |
200 | 158 | } finally { |
|
0 commit comments