ElementFromPoint 在 MDN 中有描述,但我在 Puppeteer 中找不到类似的函数。
我知道我可以将代码执行为 page.$eval
,但我想知道是否有直接的 page.elementFromPoint
API。
MDN 文档链接:
https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/elementFromPoint
最佳答案
目前,还没有为 DocumentOrShadowRoot.elementFromPoint()
显式构建的 Puppeteer 函数,但您可以使用 page.evaluate()
直接在页面 DOM 环境中执行此功能:
await page.evaluate( () => {
const example = document.elementFromPoint( 100, 100 );
example.style.color = '#f00';
});
如果需要单击或点击特定坐标处的元素,可以使用 mouse.click()
或touchscreen.tap()
:
await page.mouse.click( 100, 100 );
await page.touchscreen.tap( 100, 100 );
关于javascript - `document.elementFromPoint` 的 puppeteer api 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52598079/