Skip to content

Latest commit

 

History

History
76 lines (63 loc) · 1.63 KB

README.md

File metadata and controls

76 lines (63 loc) · 1.63 KB

WebDriver client for Golang

Build Status Go Reference

Golang bindings that conform to the W3C WebDriver and W3C WebDriver BiDi standard for controlling web browsers.

How to use

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)
}

Take Screenshots

data, err := session.TakeScreenshot()
if err != nil {
	panic(err)
}

if err := os.WriteFile("./screenshot.png", data, 0600); err != nil {
	panic(err)
}

BiDi Session

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)
}

Subscribe

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)
}

License

MIT