Last active
August 17, 2025 11:44
-
-
Save alexedwards/4a6c4385d02cf2770f1189c7ec4b6b78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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