简体   繁体   中英

Get href of link being hovered over in Puppeteer

On the page I have open in Puppeteer, I have a list of coordinates. I have a loop that uses page.mouse to hover at the positions, and I would like to get the href of the link I am hovering over, even if it's in an iframe, like in the status popup of Chrome in the bottom right corner. I tried getting window.status with page.evaluate , but it appears that Chrome always returns an empty string.

If you know that you are going to be over a link, you can use the a:hover selector.

const el = await page.$('a:hover');

So if you want to evaluate the href you can do:

const href = await.$eval('a:hover', el => el.href); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM