-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (53 loc) · 1.37 KB
/
main.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
/*
* Go automate for BrowserStack
* taken from sourcegraph go-selenium examples
*/
package main
import (
"fmt"
"github.com/rghose/go-selenium"
)
func ExampleFindElement() {
var webDriver selenium.WebDriver
var err error
remoteUrl := "http://rahulghose2:[email protected]/wd/hub"
caps := selenium.Capabilities(map[string]interface{}{
"name": "Mirage Testing Names now",
"browserName": "firefox",
"browserstack.debug": "true",
})
if webDriver, err = selenium.NewRemote(caps, remoteUrl); err != nil {
fmt.Printf("Failed to open session: %s\n", err)
return
}
defer webDriver.Quit()
err = webDriver.Get("http://www.google.com")
if err != nil {
fmt.Printf("Failed to load page: %s\n", err)
return
}
var elem selenium.WebElement
elem, err = webDriver.FindElement(selenium.ByName, "q")
if err != nil {
fmt.Printf("Failed to find element: %s\n", err)
return
}
if err = elem.SendKeys("BrowserStack"); err != nil {
fmt.Printf("Failed to send keys of element: %s\n", err)
return
}
if err = elem.Submit(); err != nil {
fmt.Printf("Failed to submit, because of: %+v", err)
return
}
if title, err := webDriver.Title(); err == nil {
fmt.Printf("Page title: %s\n", title)
} else {
fmt.Printf("Failed to get page title: %s", err)
return
}
webDriver.Quit()
}
func main() {
ExampleFindElement()
}