Golang bindings that conform to the W3C WebDriver and W3C WebDriver BiDi standard for controlling web browsers.
chromeDriver, err := webdriver.NewChromeDriver("/path/to/chromedriver")
if err != nil {
panic(err)
}
if err := chromeDriver.Start(); err != nil {
panic(err)
}
defer chromeDriver.Stop()
session, err := chromeDriver.NewSession()
if err != nil {
panic(err)
}
defer session.Close()
if err = session.NavigateTo("https://golang.org"); err != nil {
panic(err)
}
data, err := session.TakeScreenshot()
if err != nil {
panic(err)
}
if err := os.WriteFile("./screenshot.png", data, 0600); err != nil {
panic(err)
}
biDiSession, err := session.BiDiSession()
if err != nil {
panic(err)
}
bc, err := biDiSession.NewBrowsingContext(bidi.BrowsingContextTypeWindow, nil)
if err != nil {
panic(err)
}
defer bc.Close()
navigation, err := bc.Navigate("https://golang.org", bidi.BrowsingContextReadinessStateComplete)
if err != nil {
panic(err)
}
biDiSession.OnLogEntryAdded(&bidi.OnLogEntryHandler{
LogTypeConsoleHandlerFunc: func(entry *bidi.ConsoleLogEntry) error {
fmt.Println(entry)
return nil
},
})
if err := biDiSession.Subscribe([]string{"log.entryAdded"}); err != nil {
panic(err)
}