Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Simulate hover, mouseover, mouseenter for dropdown menu activation #71

Open
annjulyleon opened this issue Apr 19, 2022 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@annjulyleon
Copy link

annjulyleon commented Apr 19, 2022

I'm trying to make a screenshot for the page with dropdown menu activated.
See example here: https://demoqa.com/menu# ( .nav-menu-container #nav li:nth-child(2) :hover element).

I would appreciate any tips and workflow examples.

hover_example

@simonw
Copy link
Owner

simonw commented May 19, 2022

This looks pretty hard! https://stackoverflow.com/questions/17226676/how-do-i-simulate-a-mouseover-in-pure-javascript-that-activates-the-css-hover has a few ideas.

My hunch is that this can't be done for pure CSS :hover effects because it's not a "trusted event" as explained in https://stackoverflow.com/a/17226753/6083

@simonw simonw added the help wanted Extra attention is needed label May 19, 2022
@b-a0
Copy link

b-a0 commented Apr 29, 2024

I was looking at this as well and was hoping that the newer SO answer (with the MouseEvent) would work. Unfortunately not the case.

In my search for workarounds I did find that both puppeteer and playwright seem to be able to force a pseudostate (such as hover), but I don't understand this sufficiently.
Also, Playwright does offer a .hover() function, is that in any way usable?

@simonw
Copy link
Owner

simonw commented Apr 29, 2024

I can't figure this out either - I was hoping this would work but it didn't:

shot-scraper https://github.com/simonw/datasette/issues/2335 --javascript "
document.querySelector('.issue-shorthand').dispatchEvent(new MouseEvent('mouseover', {
    view: window,
    bubbles: true,
    cancelable: true
}));
" --wait 4000 -h 1000

That should have displayed the hover card over the first issue link on simonw/datasette#2335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants