Im writing a retweet automater bot based on node js, and its supposed to search a hashtag and randomly retweet one form the top 30 tweets and loop around and do the same for more hashtags.
it perfectly searches hashtags however, it thinks it crashed and instead errors, while I can visibally see him doing the search
// Generate a random index to select a hashtag from the list
const randomIndex = getRandomInt(0, hashtags.length);
// Select a random hashtag from the list
const hashtag = hashtags[randomIndex];
// Search for the hashtag
await page.goto(`https://twitter.com/search?q=${encodeURIComponent(`#${hashtag}`)}&src=typed_query&f=top`);
// Check if the search tab is accessible
const searchTabExists = await page.waitForSelector('div[data-testid="SearchNavigation"]', { visible: true, timeout: 5000 })
.then(() => true)
.catch(() => false);
if (!searchTabExists) {
console.log('Search tab not accessible. Taking a screenshot and exiting...');
await page.screenshot({ path: path.join(__dirname, 'ScreenShots', 'failure.png') });
break;
}
// Wait for the tweets to load
await page.waitForSelector('div[data-testid="tweet"]', { visible: true }); ```
this is the part of the code which causes the bug to happen overall.
the if !searchtabExists.
is here to fix an issue i have fixed already, But i do wanna keep it, how do I make sure it doesnt think the serach tab doesnt exists after finishing the search