尝试将输入发送到页面上的多个元素,似乎出现了校准错误之类的问题

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

你好,我遇到了校准问题,关键字输入不正确,一些输入一直进入错误的输入框。

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)

当然,您必须提供一个选择器(CSS 或 xpath),例如:

await page.waitForSelector('#foobar')
await page.type('#foobar', 'text_to_type')

您的 'hunt.email' 似乎不是有效的 CSS 选择器

您必须提供输入元素的选择器。像这样:

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)