I'm creating a puppeteer script and occasionally an "Accept Cookies" window will pop up depending on which proxy I'm using and I have a function that will press the accept button when that window pops up, but occasionally the window won't pop up and I was wondering how would I write an if/else statement to have a handling for whether the window will be visible or not. For example if cookies is visible => clicks accept | else if cookie isn't visible => ignore. I had one written up as if (cookies == true) => function | else if (cookies == null) => move on, but it didn't work as I thought. Does anyone have any ideas?
const acceptCookies = `button[class="ncss-btn-primary-dark pt3-sm pb3-sm pt2-lg pb2-lg ta-sm-c u-full-width"]`
await page.waitForSelector(acceptCookies, { visible: true });
await Promise.all([
page.click(acceptCookies),
page.waitForNavigation()
]);
await page.waitForTimeout( 2500 );