'node - How to open two tabs and run puppeteer on them
I need to fill out a form in a page with puppeteer. I have created a script that is working fine and will complete the form fields. The only problem that I'm trying to fix is that I need a working email address. What I want to do is to use tempmailo disposable email, I want to open the website inside another tab and get the generated email address from the related input field, then paste it inside the other page where the form will be filled from puppeteer and after that check if the activation email with the code is arrived. Is this possible?
I've added the code to open another page in my actual script but it will stop the form filling. Any help?
#!/usr/bin/env node
process = require('process');
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot('5xxxx', {polling: true});
const Puppeteer = require('puppeteer');
const { faker } = require('@faker-js/faker');
let newAccounts = Array;
let igAccountToIncrease = String;
let requiredFollowers = Number;
let email = String;
bot.onText(/\/add (.+)/, async (message, match) => {
const browser = await Puppeteer.launch({
headless: false,
slowMo: 300,
devtools: true,
});
const page = await browser.newPage();
await page.goto('https://www.example.com/accounts/emailsignup/');
await page.setViewport({ width: 1280, height: 607 });
await page.waitForSelector('body > .RnEpo > .pbNvD > ._1XyCr > .HoLwm')
await page.click('body > .RnEpo > .pbNvD > ._1XyCr > .HoLwm')
// after this line the script will stop filling the form and will only open the new tab
const emailPage = await browser.newPage()
const navigationPromise = emailPage.waitForNavigation()
await emailPage.goto('https://tempmailo.com/')
await emailPage.setViewport({ width: 1280, height: 607 })
await emailPage.waitForSelector('#i-email')
await emailPage.click('#i-email')
email = await emailPage.$eval('#i-email', (input) => {
return input.getAttribute('value');
});
await page.waitForSelector('input[name=emailOrPhone]')
await page.click('input[name=emailOrPhone]')
await page.type('input[name=emailOrPhone]', email, {
delay: 100
});
await page.waitForSelector('input[name=fullName]')
await page.click('input[name=fullName]')
const name = faker.name.findName();
await page.type('input[name=fullName]', name, {
delay: 100
});
console.log(name);
await page.waitForSelector('input[name=username]')
await page.click('input[name=username]')
const username = faker.internet.userName(name);
await page.type('input[name=username]', username, {
delay: 100
});
console.log(username);
await page.waitForSelector('input[name=password]')
await page.click('input[name=password]')
await page.type('input[name=password]', '1234564abc', {
delay: 100
})
await page.waitForSelector('.P8adC > .XFYOY > div > .qF0y9 > .sqdOP')
await page.click('.P8adC > .XFYOY > div > .qF0y9 > .sqdOP')
await page.waitForSelector('div > .qF0y9 > span > .O15Fw:nth-child(1) > .h144Z')
await page.click('div > .qF0y9 > span > .O15Fw:nth-child(1) > .h144Z')
await page.select('div > .qF0y9 > span > .O15Fw:nth-child(1) > .h144Z', '4')
await page.waitForSelector('div > .qF0y9 > span > .O15Fw:nth-child(2) > .h144Z')
await page.click('div > .qF0y9 > span > .O15Fw:nth-child(2) > .h144Z')
await page.select('div > .qF0y9 > span > .O15Fw:nth-child(2) > .h144Z', '25')
await page.waitForSelector('div > .qF0y9 > span > .O15Fw:nth-child(3) > .h144Z')
await page.click('div > .qF0y9 > span > .O15Fw:nth-child(3) > .h144Z')
await page.select('div > .qF0y9 > span > .O15Fw:nth-child(3) > .h144Z', '1989')
await page.waitForSelector('.rgFsT > .gr27e > .qF0y9 > .qF0y9:nth-child(7) > .sqdOP')
await page.click('.rgFsT > .gr27e > .qF0y9 > .qF0y9:nth-child(7) > .sqdOP')
await page.waitForSelector('.qF0y9 > form > .qF0y9 > .qF0y9 > .j_2Hd')
await page.click('.qF0y9 > form > .qF0y9 > .qF0y9 > .j_2Hd')
});
The website with the form is made with react, the second one with Vue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
