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

Is there a way to get css rules associated with an element ? #1016

Open
sunaynat opened this issue Feb 27, 2024 · 2 comments
Open

Is there a way to get css rules associated with an element ? #1016

sunaynat opened this issue Feb 27, 2024 · 2 comments
Labels
question Questions related to rod

Comments

@sunaynat
Copy link

Rod Version: v0.114.7

I have one element which has a css rule as

image

I want to validate this, is there a way to get the styles rules from the element ?

@sunaynat sunaynat added the question Questions related to rod label Feb 27, 2024
Copy link

Please fix the format of your markdown:

3:43 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
5:1 MD033/no-inline-html Inline HTML [Element: img]

generated by check-issue

@ysmood
Copy link
Collaborator

ysmood commented Feb 28, 2024

Yes, you can. Check the api in this file:

type CSSStyleSheetID string

rod/examples_test.go

Lines 410 to 432 in c35d2ab

// When rod doesn't have a feature that you need. You can easily call the cdp to achieve it.
// List of cdp API: https://github.com/go-rod/rod/tree/main/lib/proto
func Example_direct_cdp() {
page := rod.New().MustConnect().MustPage()
// Rod doesn't have a method to enable AD blocking,
// but you can call cdp interface directly to achieve it.
// The two code blocks below are equal to enable AD blocking
{
_ = proto.PageSetAdBlockingEnabled{
Enabled: true,
}.Call(page)
}
{
// Interact with the cdp JSON API directly
_, _ = page.Call(context.TODO(), "", "Page.setAdBlockingEnabled", map[string]bool{
"enabled": true,
})
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants