如何模糊 puppeteer 中的输入元素?

How to blur input element in puppeteer?

我正在用木偶师测试形式。 该表单具有在输入元素上发生模糊事件时触发的验证。 但是puppeteer中没有API模糊元素

我正在尝试 focusing/clicking bodydiv 元素,但这无法触发我的 onBlur 验证。 page.click("body")page.focus("body")

现在,我正在为火焰模糊事件使用虚假的点击图像。 但这不是个好办法。

export class LoginPage {
  constructor(private page: Page) {}

  async setup(): Promise<void> {
    await this.page.goto(MY_LOGIN_FORM);
  }

  async typeEmail(email: string): Promise<void> {
    await this.page.type("input[name=email]", email);
    await this.blur();
  }

  async typePassword(password: string): Promise<void> {
    await this.page.type("input[name=password]", password);
    await this.blur();
  }

  async clickLoginButton(): Promise<void> {
    await this.page.click("button");
  }

  private async blur(): Promise<void> {
    // HACK
    await this.page.click("img");
  }
}

有什么方法可以不使用 hack 来模糊输入元素?

我认为使用 $eval 甚至可能更干净一点:

await page.$eval('input[name=email]', e => e.blur());