@@ -24,30 +24,32 @@ async function selectWorkshopFromDropdown(page: Page, workshopId: string): Promi
2424 await page . waitForSelector ( '[role="listbox"]' , { timeout : 3000 } ) . catch ( ( ) => { } ) ;
2525 await page . waitForTimeout ( 200 ) ;
2626
27- // Try multiple selector patterns for Radix Select item with specific value
28- // Radix uses data-radix-collection-item and the value is in data-value
29- const selectors = [
30- `[role="option"][data-value="${ workshopId } "]` ,
31- `[data-radix-collection-item][data-value="${ workshopId } "]` ,
32- `div[role="option"]:has-text("${ workshopId . substring ( 0 , 8 ) } ")` , // partial ID match
33- ] ;
34-
35- let clicked = false ;
36- for ( const selector of selectors ) {
37- const workshopOption = page . locator ( selector ) ;
38- if ( await workshopOption . isVisible ( { timeout : 500 } ) . catch ( ( ) => false ) ) {
39- await workshopOption . click ( ) ;
40- clicked = true ;
41- break ;
42- }
43- }
27+ // Radix Select stores the value in data-value attribute on the option element
28+ // Try the data-value selector first (most reliable)
29+ const dataValueSelector = `[role="option"][data-value="${ workshopId } "]` ;
30+ const workshopOption = page . locator ( dataValueSelector ) ;
4431
45- // Fallback: click first option if nothing else worked
46- if ( ! clicked ) {
47- const firstOption = page . locator ( '[role="option"]' ) . first ( ) ;
48- if ( await firstOption . isVisible ( { timeout : 500 } ) . catch ( ( ) => false ) ) {
49- await firstOption . click ( ) ;
50- }
32+ if ( await workshopOption . isVisible ( { timeout : 1000 } ) . catch ( ( ) => false ) ) {
33+ await workshopOption . click ( ) ;
34+ } else {
35+ // If data-value selector didn't work, log and fail explicitly
36+ // Don't fall back to first option as this causes wrong workshop selection
37+ const availableOptions = await page . locator ( '[role="option"]' ) . all ( ) ;
38+ const optionValues = await Promise . all (
39+ availableOptions . map ( async ( opt ) => {
40+ const value = await opt . getAttribute ( 'data-value' ) ;
41+ const text = await opt . textContent ( ) ;
42+ return `${ value } : ${ text } ` ;
43+ } )
44+ ) ;
45+ console . error (
46+ `[selectWorkshopFromDropdown] Could not find workshop ${ workshopId } . ` +
47+ `Available options: ${ optionValues . join ( ', ' ) } `
48+ ) ;
49+ throw new Error (
50+ `Workshop ${ workshopId } not found in dropdown. ` +
51+ `Available: ${ optionValues . join ( ', ' ) } `
52+ ) ;
5153 }
5254 }
5355}
0 commit comments