@@ -576,23 +576,55 @@ async function executeJoinGroup(
576576
577577 const joinRegex = buildLocalizedRegex (
578578 runtime . selectorLocale ,
579- [ "Join" ] ,
580- [ "Deltag" , "Bliv medlem" ] ,
579+ [ "Join" , "Request to join" ] ,
580+ [ "Deltag" , "Bliv medlem" , "Anmod om at deltage" , "Anmod om at blive medlem" ] ,
581581 { exact : true }
582582 ) ;
583583 const joinButton = page . getByRole ( "button" , {
584584 name : joinRegex
585585 } ) . first ( ) ;
586+
587+ const isJoinButtonVisible = await joinButton . isVisible ( ) . catch ( ( ) => false ) ;
588+ if ( ! isJoinButtonVisible ) {
589+ const bodyTextPre = await page . locator ( "body" ) . innerText ( ) . catch ( ( ) => "" ) ;
590+ if ( / r e q u e s t e d t o j o i n / iu. test ( bodyTextPre ) ) {
591+ return {
592+ ok : true ,
593+ result : {
594+ status : "group_join_requested" ,
595+ group_id : groupId ,
596+ group_url : groupUrl
597+ } ,
598+ artifacts : [ ]
599+ } ;
600+ }
601+ if ( / j o i n e d g r o u p : | s t a r t a p o s t i n t h i s g r o u p / iu. test ( bodyTextPre ) ) {
602+ return {
603+ ok : true ,
604+ result : {
605+ status : "group_joined" ,
606+ group_id : groupId ,
607+ group_url : groupUrl
608+ } ,
609+ artifacts : [ ]
610+ } ;
611+ }
612+
613+ throw new LinkedInBuddyError (
614+ "UI_CHANGED_SELECTOR_FAILED" ,
615+ "Could not locate Join button for group." ,
616+ { group_id : groupId , group_url : groupUrl }
617+ ) ;
618+ }
619+
586620 await joinButton . click ( { timeout : 5_000 } ) ;
587621
588622 await waitForCondition ( async ( ) => {
589- const joinVisible = await page
590- . getByRole ( "button" , {
591- name : joinRegex
592- } )
593- . first ( )
594- . isVisible ( )
595- . catch ( ( ) => false ) ;
623+ if ( await isDialogVisible ( page ) ) {
624+ return true ;
625+ }
626+
627+ const joinVisible = await joinButton . isVisible ( ) . catch ( ( ) => false ) ;
596628 if ( ! joinVisible ) {
597629 return true ;
598630 }
@@ -601,6 +633,17 @@ async function executeJoinGroup(
601633 return / r e q u e s t e d t o j o i n | j o i n e d g r o u p : / iu. test ( bodyText ) ;
602634 } , 8_000 ) ;
603635
636+ if ( await isDialogVisible ( page ) ) {
637+ // Dismiss the dialog if possible to avoid state bleeding
638+ await page . getByRole ( "button" , { name : buildLocalizedRegex ( runtime . selectorLocale , [ "Close" , "Dismiss" ] , [ "Luk" , "Afvis" ] ) } ) . first ( ) . click ( ) . catch ( ( ) => { } ) ;
639+
640+ throw new LinkedInBuddyError (
641+ "ACTION_PRECONDITION_FAILED" ,
642+ "Group requires answering questions to join." ,
643+ { group_id : groupId , group_url : groupUrl }
644+ ) ;
645+ }
646+
604647 const bodyText = await page . locator ( "body" ) . innerText ( ) . catch ( ( ) => "" ) ;
605648 const status = / r e q u e s t e d t o j o i n / iu. test ( bodyText )
606649 ? "group_join_requested"
0 commit comments