easrng
easrng

Reputation: 445

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.

Upvotes: 0

Views: 445

Answers (1)

hardkoded
hardkoded

Reputation: 21695

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); 

Upvotes: 1

Related Questions