Skip to content

Commit 46f6be2

Browse files
authored
fix: resolve company unfollow verification error (#571) (#584)
1 parent a5f3226 commit 46f6be2

File tree

1 file changed

+82
-2
lines changed

1 file changed

+82
-2
lines changed

packages/core/src/linkedinCompanyPages.ts

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,75 @@ async function waitForCondition(
291291
return condition();
292292
}
293293

294+
295+
function buildCompanyMenuActionCandidates(input: {
296+
selectorLocale: LinkedInSelectorLocale;
297+
selectorKeys: LinkedInSelectorPhraseKey | readonly LinkedInSelectorPhraseKey[];
298+
candidateKeyPrefix: string;
299+
}): VisibleLocatorCandidate[] {
300+
const exactRegex = buildLinkedInSelectorPhraseRegex(
301+
input.selectorKeys,
302+
input.selectorLocale,
303+
{ exact: true }
304+
);
305+
const exactRegexHint = formatLinkedInSelectorRegexHint(
306+
input.selectorKeys,
307+
input.selectorLocale,
308+
{ exact: true }
309+
);
310+
const textRegex = buildLinkedInSelectorPhraseRegex(
311+
input.selectorKeys,
312+
input.selectorLocale
313+
);
314+
const textRegexHint = formatLinkedInSelectorRegexHint(
315+
input.selectorKeys,
316+
input.selectorLocale
317+
);
318+
319+
return [
320+
{
321+
key: `${input.candidateKeyPrefix}-menu-roleitem`,
322+
selectorHint: `[role='menuitem'] hasText ${exactRegexHint}`,
323+
locatorFactory: (page) =>
324+
page.locator("[role='menuitem']").filter({
325+
hasText: exactRegex
326+
})
327+
},
328+
{
329+
key: `${input.candidateKeyPrefix}-menu-dropdown-item`,
330+
selectorHint: `.artdeco-dropdown__content-inner [role='button'] hasText ${exactRegexHint}`,
331+
locatorFactory: (page) =>
332+
page.locator(".artdeco-dropdown__content-inner [role='button']").filter({
333+
hasText: exactRegex
334+
})
335+
},
336+
{
337+
key: `${input.candidateKeyPrefix}-menu-li-text`,
338+
selectorHint: `.artdeco-dropdown__content-inner li hasText ${textRegexHint}`,
339+
locatorFactory: (page) =>
340+
page.locator(".artdeco-dropdown__content-inner li").filter({
341+
hasText: textRegex
342+
})
343+
},
344+
{
345+
key: `${input.candidateKeyPrefix}-modal-primary-btn`,
346+
selectorHint: `.artdeco-modal button.artdeco-button--primary hasText ${exactRegexHint}`,
347+
locatorFactory: (page) =>
348+
page.locator(".artdeco-modal button.artdeco-button--primary").filter({
349+
hasText: exactRegex
350+
})
351+
},
352+
{
353+
key: `${input.candidateKeyPrefix}-modal-btn`,
354+
selectorHint: `.artdeco-modal button hasText ${exactRegexHint}`,
355+
locatorFactory: (page) =>
356+
page.locator(".artdeco-modal button").filter({
357+
hasText: exactRegex
358+
})
359+
}
360+
];
361+
}
362+
294363
function buildCompanyActionButtonCandidates(input: {
295364
root: Locator;
296365
selectorLocale: LinkedInSelectorLocale;
@@ -708,15 +777,26 @@ async function executeUnfollowCompanyPage(
708777
);
709778
}
710779

711-
const selectorKey = await clickCompanyAction({
780+
let selectorKey = await clickCompanyAction({
712781
page,
713782
selectorLocale: runtime.selectorLocale,
714-
selectorKeys: "following",
783+
selectorKeys: ["unfollow", "following"],
715784
actionLabel: "Unfollow",
716785
targetCompany,
717786
candidateKeyPrefix: "company-unfollow"
718787
});
719788

789+
const confirmCandidates = buildCompanyMenuActionCandidates({
790+
selectorLocale: runtime.selectorLocale,
791+
selectorKeys: "unfollow",
792+
candidateKeyPrefix: "company-unfollow-confirm"
793+
});
794+
const confirmAction = await findVisibleLocator(page, confirmCandidates);
795+
if (confirmAction) {
796+
await confirmAction.locator.click({ timeout: 5_000 });
797+
selectorKey = `${selectorKey}:${confirmAction.key}`;
798+
}
799+
720800
const unfollowed = await waitForCondition(async () => {
721801
const nextState = await readCompanyFollowState(
722802
page,

0 commit comments

Comments
 (0)