【问题标题】:Javascript Puppeteer Error: Node is either not clickable or not an HTMLElementJavascript Puppeteer 错误:节点不可点击或不是 HTMLElement
【发布时间】:2022-01-22 08:29:40
【问题描述】:

如果我尝试单击这样的元素,我会收到错误:

const handle = await page.$('.days-label.col-md-12.desktop div:nth-child(1)');
await handle.click();

但是,如果我像这样单击它,它会起作用:

await page.$eval('.days-label.col-md-12.desktop div:nth-child(1)', el => el.click()); 

我尝试通过等待选择器和导航来修复它,但仍然是同样的错误:

await page.waitForSelector('.days-label.col-md-12.desktop div:nth-child(1)');
const handle = await page.$('.days-label.col-md-12.desktop div:nth-child(1)');
await Promise.all([
    page.waitForNavigation(),
    handle.click(),
]);

【问题讨论】:

  • 为什么不使用有效的呢?这种行为是known

标签: javascript node.js web-scraping puppeteer


【解决方案1】:

waitForSelector() 返回<Promise<?ElementHandle>>

const handle = await page.waitForSelector(
  '.days-label.col-md-12.desktop div:nth-child(1)'
)
await Promise.all([
    page.waitForNavigation(),
    handle.click(),
])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多