Skip to content

Instantly share code, notes, and snippets.

@alexedwards
Last active August 17, 2025 11:44
Show Gist options
  • Save alexedwards/4a6c4385d02cf2770f1189c7ec4b6b78 to your computer and use it in GitHub Desktop.
Save alexedwards/4a6c4385d02cf2770f1189c7ec4b6b78 to your computer and use it in GitHub Desktop.
import (
"strings"
"testing"
"golang.org/x/net/html"
"github.com/andybalholm/cascadia"
)
func containsHTMLNode(t *testing.T, htmlBody, cssSelector string) bool {
doc, err := html.Parse(strings.NewReader(htmlBody))
if err != nil {
t.Fatal(err)
}
selector, err := cascadia.Compile(cssSelector)
if err != nil {
t.Fatal(err)
}
return cascadia.Query(doc, selector) != nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment