-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebdriver.go
40 lines (34 loc) · 1.17 KB
/
webdriver.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
38
39
package main
import (
"fmt"
"os"
"github.com/tebeka/selenium"
)
func getWebDriver() selenium.WebDriver {
const (
// These paths will be different on your system.
seleniumPath = "vendor/selenium-server-standalone-3.4.0.jar"
geckoDriverPath = "vendor/geckodriver-v0.18.0-linux64"
port = 8080
)
opts := []selenium.ServiceOption{
selenium.StartFrameBuffer(), // Start an X frame buffer for the browser to run in.
selenium.GeckoDriver(geckoDriverPath), // Specify the path to GeckoDriver in order to use Firefox.
selenium.Output(os.Stderr), // Output debug information to STDERR.
}
selenium.SetDebug(true)
selenium.NewSeleniumService(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": "firefox"}
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
if err != nil {
panic(err)
}
// defer wd.Quit()
return wd
}