Hover on element and getComputedStyle in Node.js using Puppeteer?

自作多情 提交于 2021-02-19 05:31:16

问题


I want to hover on some element, let say document.getElementById("abc") and find its hover computed style.

How should I do it in Node.js using Puppeteer?


回答1:


You can use the following solution to iterate and hover over certain elements to obtain the computed style:

const elements = await page.$$('.abc');
const data = [];

for (let i = 0; i < elements.length; i++) {
  await elements[i].hover();
  data.push(await page.evaluate(element => window.getComputedStyle(element), elements[i]));
}

console.log(data);


来源:https://stackoverflow.com/questions/52165320/hover-on-element-and-getcomputedstyle-in-node-js-using-puppeteer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!