How to add xpath in a click function?

The Click function using a CSS Selector is const buttonSelector = cssSelector; {some function} $(buttonSelector).click(); But, When I use Css Selector, the clicking goes on an endless loop, since adding more attributes doesnt work with CSS Selector. So, I decided to use Xpath and modified the code like follows, but, I am getting a syntax error. const buttonSelector = document.querySelector('//Xpath'); {some function} $(buttonSelector).click(); How can I correct this to make it work?
6 Replies
metropolitan-bronze
metropolitan-bronzeOP3y ago
I checked these and couldnt find a solution.
afraid-scarlet
afraid-scarlet3y ago
If you not getting clickable element by document.evaluate then try to get element by Puppeteer or PW and call click() from framework. If both approached does not work review your data flow since well, scrapers able to do clicks, if your clicks does not work you doing it somehow in a wrong way
metropolitan-bronze
metropolitan-bronzeOP3y ago
My click works when I use css selector, but it goes on an infinite loop. When I use document.evaluate with xpath, its not detecting the next page button. I am using the apify/webscraper , so, I am not sure how to use puppeteer in it, do I have to code in the puppeteer crawler?
afraid-scarlet
afraid-scarlet3y ago
yes, I think so: https://apify.com/apify/web-scraper#page-function not provide page object in context so you need either pptr crawler or your own actor
metropolitan-bronze
metropolitan-bronzeOP3y ago
Ok, Thanks, I will try that.

Did you find this page helpful?