Home > Back-end >  hover over elements to activate child element to click?
hover over elements to activate child element to click?

Time:12-10

I try to select all photos from whatsapp web with this:

document.querySelectorAll('._33mBu > span').forEach(s => s.click()) 

But it seems that you first have to hover over each photo (class '_23fpc') to make this class '_33mBu' visible. Is there a way to do this?

CodePudding user response:

If it has to do something with the mouseover (or maybe the mouseenter) event, this might be worth a shot:

const mouseoverEvent = new Event('mouseover');
document.querySelectorAll("._23fpc").forEach(s => s.dispatchEvent(mouseoverEvent));

If it works, you can go on with the code you provided.

CodePudding user response:

Since you've got this in the jQuery category, here's a JQ way of approaching it. The unknown bit is what the mouseover is doing... it might be triggering some kind of async event before it writes to the page. I have put in a little delay after mouseover which you might need to edit

$("._23fpc").each(function () {
  $(this).trigger('mouseenter');
  doMO($(this));
})

function doMO($el) {
 setTimeout(() => {
   $el.trigger('click');
 }, 100)
}
  • Related