-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenviando_contato.js
48 lines (33 loc) · 1.39 KB
/
enviando_contato.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const puppeteer = require('puppeteer');
(async function main() {
try{
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36');
await page.goto('https://web.whatsapp.com/');
await page.waitForSelector('.to2l77zo', { timeout: 30000 });
await delay(5000);
const contactName = "Amor💕";
await page.click(`span[title='${contactName}']`);
await page.waitForSelector("._11JPr");
const editor = await page.$('div[title="Digite uma mensagem"][contenteditable="true"]');
await editor.focus();
const amountOfMessages = 5;
for (let i = 0; i < amountOfMessages; i++) {
await page.evaluate(() => {
const message = "teste disparador - Oi amor Te amo";
document.execCommand('insertText', false, message);
});
const sendButtonSelector = 'button[aria-label="Enviar"]';
await page.click(sendButtonSelector);
await delay(500);
}
} catch (e) {
console.error("error mine", e);
}
})();
function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time);
});
}