| 79 | } |
| 80 | |
| 81 | async function selectNativeSelectOption( |
| 82 | handle: ElementHandle<Element>, |
| 83 | signal: AbortSignal, |
| 84 | ): Promise<boolean> { |
| 85 | using selectHandle = await handle.evaluateHandle(node => { |
| 86 | if (!(node instanceof HTMLOptionElement)) { |
| 87 | return null; |
| 88 | } |
| 89 | |
| 90 | const select = node.closest('select'); |
| 91 | if (!select || select.multiple || select.disabled || node.disabled) { |
| 92 | return null; |
| 93 | } |
| 94 | |
| 95 | const parentElement = node.parentElement; |
| 96 | if ( |
| 97 | parentElement instanceof HTMLOptGroupElement && |
| 98 | parentElement.disabled |
| 99 | ) { |
| 100 | return null; |
| 101 | } |
| 102 | |
| 103 | return select; |
| 104 | }); |
| 105 | |
| 106 | using select = selectHandle.asElement() as ElementHandle<Element> | null; |
| 107 | if (!select) { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | using valueHandle = await handle.getProperty('value'); |
| 112 | |
| 113 | const value = await valueHandle.jsonValue(); |
| 114 | if (typeof value !== 'string') { |
| 115 | return false; |
| 116 | } |
| 117 | await select.asLocator().fill(value, {signal}); |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | export const click: PageToolFactory = definePageTool(() => ({ |
| 123 | name: 'click', |