From 7a025ad78be8234f71c20db5a252415d5e5b13b7 Mon Sep 17 00:00:00 2001 From: bossgeekgo Date: Sat, 10 Feb 2024 10:20:26 +0800 Subject: [PATCH] fix variable scope issue; fix execute too early caused cannot find element. --- main/index.mjs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main/index.mjs b/main/index.mjs index 1dcfa0f..3f1561b 100644 --- a/main/index.mjs +++ b/main/index.mjs @@ -45,7 +45,10 @@ async function mainLoop () { await page.setCookie(bossCookies[i]); } - await page.goto(recommendJobPageUrl, { timeout: 0 }) + await Promise.all([ + page.goto(recommendJobPageUrl, { timeout: 0 }), + page.waitForNavigation(), + ]) await sleepWithRandomDelay(2500) @@ -58,15 +61,14 @@ async function mainLoop () { const currentActiveJobIndex = await page.evaluate(` [...document.querySelectorAll('.job-recommend-search .recommend-job-btn')].findIndex(it => it.classList.contains('active')) `) + + const expectJobList = await page.evaluate(`document.querySelector('.job-recommend-search')?.__vue__?.expectList`) if (currentActiveJobIndex === currentExceptJobIndex) { // first navigation and can immediately start chat (recommend job) } else { // not first navigation and should choose a job (except job) - const expectJobList = await page.evaluate(`document.querySelector('.job-recommend-search')?.__vue__?.expectList`) - - const expectJobTabHandlers = await page.$$('.job-recommend-main .recommend-search-expect .recommend-job-btn') - // click first expect job + const expectJobTabHandlers = await page.$$('.job-recommend-main .recommend-search-expect .recommend-job-btn') await expectJobTabHandlers[currentExceptJobIndex].click() await page.waitForResponse( response => { @@ -219,7 +221,7 @@ async function mainLoop () { } catch (err) { if (err instanceof Error && err.message === 'CANNOT_FIND_EXCEPT_JOB') { if ( - currentExceptJobIndex + 1 > expectJobTabHandlers.length + currentExceptJobIndex + 1 > expectJobList.length ) { await Promise.all([ page.reload(),