-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[Feature] CSS.forcePseudoState #3347
Comments
One way I could solve the issue is to have a way to access the CDP client/session of a frame or an elementHandle |
This issue looks pretty similar to #3345 |
Yeah they look very similar. Sorry I did not see it before posting |
Could you share more on your use case? |
The idea is to let a user select an element in the page but I'd like to keep it "activated". And some elements only stay visible on hover. |
@gilles-yvetot do I get it right that you want to "activate" the pseudo element, keep it in that state and and the let the user select it? If so, can you clarify what is the user action that would "select" the pseudo-element? |
@yury-s I want to activate the CSS pseudo state, like But the real question is more to be able to access the CDP client/session of an elementHandle to retrieve the |
You could create CDP session for the page and then evaluate node id using CDP commands, not much help from playwright in that case but it should solve your problem. |
@yury-s Yep that's what I ended up doing. But I could not use XPath though. So I converted my XPath to a classic query selector then start forcing |
@gilles-yvetot Did you manage to find |
@dgozman thanks a lot! Yeah I have a working solution:
|
@gilles-yvetot Wonderful! Feel free to ask more questions when the help is needed. |
How did you do it? could you share a snippet? |
For posterity, I had to do something similar, and this is what it looked like in code. Converting the Path to a selector: Enabling CSS and DOM: await cdp().send("DOM.enable")
await cdp().send("CSS.enable") From here, I skip to forcing the pseudo class. I did not need to get the document, as I did not desire toggling const nodeId = await getNodeId(element)
await cdp().send("CSS.forcePseudoState", { nodeId, forcedPseudoClasses: ["hover"] }) |
Hello there,
Thanks for the great work done on pptr and now on pw 👍
I have been trying to force the CSS pseudo state of an element to hover. I want this css state to be "permanent" so I cannot use
elementHandle.hover()
. I have trying to use a CDP session to do that but it is very hard to find thenodeId
needed to call this function. Especially when you work with extension iframes (I could not find a way to identify an element by its XPath).Thanks a lot
The text was updated successfully, but these errors were encountered: