-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchromeWebDriver.go
38 lines (32 loc) · 1.02 KB
/
chromeWebDriver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"os"
"github.com/tebeka/selenium"
)
func getChromeWebDriver() selenium.WebDriver {
const (
// These paths will be different on your system.
seleniumPath = "vendor/selenium-server-standalone-3.4.0.jar"
port = 8080
)
opts := []selenium.ServiceOption{
selenium.StartFrameBuffer(), // Start an X frame buffer for the browser to run in.
selenium.Output(os.Stderr), // Output debug information to STDERR.
}
selenium.SetDebug(true)
selenium.NewChromeDriverService(seleniumPath, port, opts...)
//service, err := selenium.NewSeleniumService(seleniumPath, port, opts...)
//if err != nil {
// panic(err) // panic is used only as an example and is not otherwise recommended.
//}
//defer service.Stop()
// Connect to the WebDriver instance running locally.
caps := selenium.Capabilities{"browserName": "chrome"}
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
if err != nil {
panic(err)
}
// defer wd.Quit()
return wd
}