Use geckodriver directly without selenium

This commit is contained in:
Chandler Swift 2021-10-18 17:43:46 -05:00
parent b69caa160b
commit b0af949397
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F

18
main.go
View file

@ -126,25 +126,23 @@ func main() {
flag.Parse() flag.Parse()
const ( const (
// These paths will be different on your system.
seleniumPath = "deps/selenium-server-standalone-3.141.59.jar"
geckoDriverPath = "deps/geckodriver" geckoDriverPath = "deps/geckodriver"
seleniumPort = 8080 geckoDriverPort = 8080
) )
opts := []selenium.ServiceOption{ opts := []selenium.ServiceOption{
selenium.StartFrameBuffer(), // Start an X frame buffer for the browser to run in. selenium.StartFrameBuffer(),
selenium.GeckoDriver(geckoDriverPath), // Specify the path to GeckoDriver in order to use Firefox.
selenium.Output(nil), selenium.Output(nil),
} }
selenium.SetDebug(true) selenium.SetDebug(true)
service, err := selenium.NewSeleniumService(seleniumPath, seleniumPort, opts...)
service, err := selenium.NewGeckoDriverService(geckoDriverPath, geckoDriverPort, opts...)
if err != nil { if err != nil {
panic(err) // panic is used only as an example and is not otherwise recommended. panic(err)
} }
defer service.Stop() defer service.Stop()
// Connect to the WebDriver instance running locally.
caps := selenium.Capabilities{"browserName": "firefox"} wd, err := selenium.NewRemote(nil, fmt.Sprintf("http://localhost:%d", geckoDriverPort))
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", seleniumPort))
if err != nil { if err != nil {
panic(err) panic(err)
} }