Puppeteer: TypeError: page.waitForXpath is not a function

Puppeteer: TypeError: page.waitForXpath is not a function

我正在使用此代码。代码的输出总是显示 TypeError: page.waitForXpath is not a function。 Puppeteer 版本:8.0.0 和 puppeteer-xpath 版本:0.1.0 我也使用此命令进行升级:npm install https://github.com/GoogleChrome/puppeteer/ 但这不起作用。这是我的代码:

const { expect } = require('chai');
const puppeteer = require('puppeteer');

var browser, page;
before(async () => {
  browser = await puppeteer.launch({
    headless: false,
    defaultViewport: null,
    devtools: false,
    args: [
        "--disable-web-security",
        "--disable-features=IsolateOrigins,site-per-process",
        "--window-size=1920,1080"
    ]
 });
 page = await browser.newPage();
})
describe("Search to google", async () => {
  it("write something to searchbar", async () => {

    await page.goto("https://www.google.com");
    let searchBarSelector = '[name=q]';
    await page.waitForSelector(searchBarSelector);
    let [searchBarElement] = await page.$$(searchBarSelector);
    await searchBarElement.type("JavaScript Tutorial");
    // await page.type(searchBarSelector,"JavaScript Tutorial");
    await page.keyboard.press("Enter");

    let imageXpath = "//a[contains(text(),'Images')]";
    await page.waitForXpath(imageXpath);
    let imageTextElement = await page.$x(imageXpath);
    expect(imageTextElement != null).equals(true);


  })
})
after(async () => {
   await browser.close();
})

输出:

您只是打错了字:是 page.waitForXPath(),而不是 page.waitForXpath()

请参阅文档中的 page.waitForXPath(xpath[, options])