Riz
Riz

Reputation: 51

Puppeteer removing input field data on page.WaitFor()

I have a website login form I'm trying to log in to, I was able to get the username and password to type into the input forms. Then I wanted to wait submit the form, but when I do a page.Waitfor(), it seems to wipe out the input data fields. Can someone explain why or show a workaround?

async function Scraper(){
try{

  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36');
  await page.goto('https://onlyfans.com/');

await page.waitFor('input[name=email]');

console.log("starting to do this");

await page.$eval('input[name=email]', el => el.value = '[email protected]');
await page.$eval('input[name=password]', el => el.value = 'xxx');

let selector = 'button[type="submit"]';

await page.screenshot({
  path: 'yoursite.png',
  fullPage: true
});

  await page.waitFor(5000);

  await page.evaluate((selector) => document.querySelector(selector).click(), selector); 


await page.screenshot({
path: 'yoursite4.png',
fullPage: true});

console.log("done");

Here is the differences between the two images:

enter image description here

enter image description here

Upvotes: 0

Views: 402

Answers (1)

mbit
mbit

Reputation: 3033

Looks like there is a delay till the login button gets enabled. The following worked for me:

await page.goto('https://onlyfans.com/', {waitUntil: "networkidle0"});

await page.waitForSelector('input[name=email]');
await page.waitForSelector('input[name=password]');
await page.waitForSelector('button[type="submit"]');

await page.type('input[name=email]', '[email protected]', {delay: 200});
await page.type('input[name=password]', 'xxx', {delay: 200});

await page.click('button[type="submit"]');

Upvotes: 2

Related Questions