forked from tebeka/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
80 lines (64 loc) · 1.94 KB
/
doc.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Package selenium provider a Selenium/Webdriver client.
Currently provides only WebDriver remote client.
This means you'll need to run the Selenium server by yourself (or use a service
like SauceLabs). The easiest way to do that is to grab the Selenium server jar
from http://www.seleniumhq.org/download/ and run it
java -jar selenium-server-standalone-2.24.1.jar
To use the webdriver with firefox, you may (depending on versions) require the
gecko driver package. You can download it here
https://github.com/mozilla/geckodriver/releases
and configure the webdriver in your Go code like this
caps := selenium.Capabilities{
"browserName": "firefox",
"webdriver.gecko.driver": "/path/to/downloaded/geckodriver",
}
Example usage:
// Run some code on play.golang.org and display the result
package main
import (
"fmt"
"time"
"github.com/tebeka/selenium"
)
var code = `
package main
import "fmt"
func main() {
fmt.Println("Hello WebDriver!\n")
}
`
// Errors are ignored for brevity.
func main() {
// FireFox driver without specific version
// *** Add gecko driver here if necessary (see notes above.) ***
caps := selenium.Capabilities{"browserName": "firefox"}
wd, err := selenium.NewRemote(caps, "")
if err != nil {
panic(err)
}
defer wd.Quit()
// Get simple playground interface
wd.Get("http://play.golang.org/?simple=1")
// Enter code in textarea
elem, _ := wd.FindElement(selenium.ByCSSSelector, "#code")
elem.Clear()
elem.SendKeys(code)
// Click the run button
btn, _ := wd.FindElement(selenium.ByCSSSelector, "#run")
btn.Click()
// Get the result
div, _ := wd.FindElement(selenium.ByCSSSelector, "#output")
output := ""
// Wait for run to finish
for {
output, _ = div.Text()
if output != "Waiting for remote server..." {
break
}
time.Sleep(time.Millisecond * 100)
}
fmt.Printf("Got: %s\n", output)
}
*/
package selenium