I've seen so many posts (for example, see here and here), saying that I could click on something via the following code,
await page.click('.route-redirect-box'); // via Puppeteer page.click
await page.evaluate((css_selector) => {
document.querySelector(css_selector).click(); // or via page.evaluate
}, css);
However, as I tested on some websites, looks like page.click always works, but page.evaluate doesn't, using headless: false mode.
For example, this website page, I tried to click on something as follows,
var css = '#searchPaginationTop > nav > a:nth-child(5)';
await page.evaluate((css_selector) => { document.querySelector(css_selector).click();}, css);
nothing happened at all, but if I use page.click, it worked as expected.
I'm thinking that, the element I wanted to click is not a normal clickable element, since the html code for that element is as follows,
<a class="svg" data-goto-page="3" data-total-pages="3" data-ga="event" data-ga-category="Brands at allbeauty-Burberry-Pagination" data-ga-action="Brands at allbeauty-Burberry-Pagination-Next-Touch" data-ga-label="Brands at allbeauty-Burberry-Pagination-Next-Link">
<svg viewBox="0 0 21.9 38.7" alt="Next Page" title="Next Page ">
<use xlink:href="#icon-ab-arrow-right">
</use>
</svg>
</a>
Could it be because this element is some data-ga stuff, so page.evaluate cannot click on it?