Search code examples
webdriverweb-crawlerpuppeteerwebautomation

Trying to send input to multiple elements on a page, seems to be having something like a calibration error


hello i am having something like a calibration problem, the keywords are not going in the right way, some inputs keep going into the wrong input box.

page.waitFor(3*1000);
    await page.waitForSelector(hunt.email, {
      visible : true,
    });
    await page.type(hunt.email, user.email);
    page.waitFor(1000);
    await page.type(hunt.firstname, user.firstName);
    page.waitFor(5*1000);
    await page.type(hunt.lastname, user.lastName);
    await page.type(hunt.company, user.company);
    page.waitFor(5*1000);
    await page.type(hunt.address, user.address);
    page.waitFor(5*1000);
    await page.type(hunt.city, user.city)
    page.waitFor(5*1000);
    await page.type(hunt.phone, user.phone)

Solution

  • You must provide selector of the input element. Like this:

    const user = {
        email : 'donald.trump@gmail.com',
        firstName : 'Donald',
        lastName : 'Trump',
        company : 'United States of America',
        address : 'White House, Wall Street',
        city : 'Washington',
        phone : '123456789'
    }
    
    const hunt = {
        email : 'input[name="email"]',
        firstname : 'input[name="firstname"]',
        lastname : 'input[name="lastname"]',
        company : 'input[name="company"]',
        address : 'input[name="address"]',
        city : 'input[name="city"]',
        phone : 'input[name="phone"]'
    }
    
    await page.waitForSelector(hunt.email, { timeout: 0 })
    await page.click(hunt.email)
    await page.keyboard.type(user.email)
    
    await page.waitForSelector(hunt.firstname, { timeout: 0 })
    await page.click(hunt.firstname)
    await page.keyboard.type(user.firstName)
    
    await page.waitForSelector(hunt.lastname, { timeout: 0 })
    await page.click(hunt.lastname)
    await page.keyboard.type(user.lastName)
    
    await page.waitForSelector(hunt.company, { timeout: 0 })
    await page.click(hunt.company)
    await page.keyboard.type(user.company)
    
    await page.waitForSelector(hunt.address, { timeout: 0 })
    await page.click(hunt.address)
    await page.keyboard.type(user.address)
    
    await page.waitForSelector(hunt.city, { timeout: 0 })
    await page.click(hunt.city)
    await page.keyboard.type(user.city)
    
    await page.waitForSelector(hunt.phone, { timeout: 0 })
    await page.click(hunt.phone)
    await page.keyboard.type(user.phone)