| 99 | } |
| 100 | |
| 101 | async function selectNativeSelectOption( |
| 102 | handle: ElementHandle<Element>, |
| 103 | signal: AbortSignal, |
| 104 | ): Promise<boolean> { |
| 105 | using selectHandle = await handle.evaluateHandle(node => { |
| 106 | if (!(node instanceof HTMLOptionElement)) { |
| 107 | return null; |
| 108 | } |
| 109 | |
| 110 | const select = node.closest('select'); |
| 111 | if (!select || select.multiple || select.disabled || node.disabled) { |
| 112 | return null; |
| 113 | } |
| 114 | |
| 115 | const parentElement = node.parentElement; |
| 116 | if ( |
| 117 | parentElement instanceof HTMLOptGroupElement && |
| 118 | parentElement.disabled |
| 119 | ) { |
| 120 | return null; |
| 121 | } |
| 122 | |
| 123 | return select; |
| 124 | }); |
| 125 | |
| 126 | using select = selectHandle.asElement() as ElementHandle<Element> | null; |
| 127 | if (!select) { |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | using valueHandle = await handle.getProperty('value'); |
| 132 | |
| 133 | const value = await valueHandle.jsonValue(); |
| 134 | if (typeof value !== 'string') { |
| 135 | return false; |
| 136 | } |
| 137 | await select.asLocator().fill(value, {signal}); |
| 138 | |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | export const click: PageToolFactory = definePageTool(() => ({ |
| 143 | name: 'click', |