Reputation: 1389
So I am trying to log out from Reddit.com using Puppeteer and it just sends me back to the link of the page instead of actually loging out. I am given to understand that this occurs due to the fact that it is written in Reactjs and therefore the click is being handled via a listener and then dispatched through Redux to log the user out.
Is this a preventive measure that has been put into place or there is a way go around this?
The log out code for Reddit for me is as follows and it can be seen that the a
tag refers to "/"
which is the homepage and by clicking it by Puppeteer I only get to go to homepage instead of actually loging out.
<a data-redditstyle="true" class="_1YWXCINvcuU7nk0ED-bta8" href="/"><svg class="_2BQPq3iyS8t6kKtFmtkB30 " viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><g fill="inherit"><path d="M15,2 L5,2 C4.447,2 4,2.447 4,3 L4,9 L9.586,9 L8.293,7.707 C7.902,7.316 7.902,6.684 8.293,6.293 C8.684,5.902 9.316,5.902 9.707,6.293 L12.707,9.293 C13.098,9.684 13.098,10.316 12.707,10.707 L9.707,13.707 C9.512,13.902 9.256,14 9,14 C8.744,14 8.488,13.902 8.293,13.707 C7.902,13.316 7.902,12.684 8.293,12.293 L9.586,11 L4,11 L4,17 C4,17.553 4.447,18 5,18 L15,18 C15.553,18 16,17.553 16,17 L16,3 C16,2.447 15.553,2 15,2"></path></g></svg><div class="vzhy90YD0qH7ZDJi7xMGw">Log Out</div></a>
Upvotes: 0
Views: 133
Reputation: 18836
Use this xpath to click,
const logoutBtn = await page.$x(`//*[contains(text(),'Log Out')]`);
// returns a array of element handles that we can click
await logoutBtn[0].click();
And/or, Clear the cookies and history so you are automagically logged out,
const client = await page.target().createCDPSession();
await client.send('Network.clearBrowserCookies');
await client.send('Network.clearBrowserCache');
Upvotes: 1