3

I've tried almost anything but still unable to insert username after clicking input. I know there is other solutions to do so without clicking I also tried but still not working...

Click is working and cursor blinking now all I need is just to 'type' something.

const puppeteer = require('puppeteer');

const creds = {
    email: "myemail",
    password: "mypassword",
};

(async () => {
    const browser = await puppeteer.launch({headless: false, args: ['--start-maximized']});
    const page = await browser.newPage();
    //set viewport
    await page.setViewport({
        width: 1920,
        height: 1080,
    })
    await page.goto('https://qa.traffilog.co.il/new_web/index.htm', {waitUntil: 'networkidle0'});
    const username = await page.$x('/html/body/div[1]/div/div[1]/div/div[2]/div/div[1]/div/div[2]/div/div[3]/div/div[1]/div/div/div/div/div/div[2]/div/div[1]/div/input[1]');

    await username[0].click();
    await page.waitForNavigation({ waitUntil: 'networkidle0' });
    await page.type(username, creds.email);
    await page.waitForNavigation({ waitUntil: 'networkidle0' });


    // await browser.close();
})

();
Aviran
  • 15
  • 5
  • You can use type without specifying a target. You can also use page.keyboard.press() – John Dec 23 '20 at 20:55

1 Answers1

0

From what I've read in the docs Page.type takes a selector not an ElementHandle. But because you are using an ElementHandle you could try to set the input value by using username[0].value=creds.email

PhantomSpooks
  • 2,877
  • 2
  • 8
  • 13