Created
December 31, 2024 17:43
-
-
Save lucianodiisouza/d2ba237d967ebc07c986620d74512588 to your computer and use it in GitHub Desktop.
Puppteer code to send whatsapp message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "npm init -y" will start a node project | |
// "npm i puppeteer" install puppeteer lib on your project | |
// at the end run "node index.js" to execute this code. | |
// Be carefull with the selectors inside the "waitForSelector" sections, they are just css selects that could change | |
const puppeteer = require('puppeteer'); | |
(async () => { | |
const browser = await puppeteer.launch({ headless: false }); | |
const page = await browser.newPage(); | |
await page.goto('https://web.whatsapp.com'); | |
console.log('Escaneie o QR code com seu WhatsApp para continuar.'); | |
await page.waitForSelector(' .x1whj5v', { timeout: 60000 }); | |
const contactName = 'Clube das Winx'; | |
const message = 'Feliz Ano Novo! 🎉🎆 Que 2024 seja incrível para você! (teste do puppeteer)'; | |
await page.type('.x1whj5v', contactName); | |
await page.keyboard.press('Enter'); | |
await page.waitForSelector('.x15bjb6t'); | |
const inputBox = await page.$('.x15bjb6t'); | |
await inputBox.type(message); | |
await inputBox.press('Enter'); | |
console.log('Mensagem enviada com sucesso!'); | |
await browser.close(); | |
})(); | |
// OPrimoDev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment