Use geckodriver directly without selenium
This commit is contained in:
parent
b69caa160b
commit
b0af949397
18
main.go
18
main.go
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue