-
Notifications
You must be signed in to change notification settings - Fork 21
/
remote_driver_document.go
59 lines (45 loc) · 1.44 KB
/
remote_driver_document.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
package goselenium
import "fmt"
// PageSourceResponse is the response returned from calling the PageSource
// method.
type PageSourceResponse struct {
State string
Source string
}
// ExecuteScriptResponse is the response returned from calling the ExecuteScript
// method.
type ExecuteScriptResponse struct {
State string
Response string
}
func (s *seleniumWebDriver) PageSource() (*PageSourceResponse, error) {
if len(s.sessionID) == 0 {
return nil, newSessionIDError("PageSource")
}
var err error
url := fmt.Sprintf("%s/session/%s/source", s.seleniumURL, s.sessionID)
resp, err := s.valueRequest(&request{
url: url,
method: "GET",
body: nil,
callingMethod: "PageSource",
})
if err != nil {
return nil, err
}
return &PageSourceResponse{State: resp.State, Source: resp.Value}, nil
}
func (s *seleniumWebDriver) ExecuteScript(script string) (*ExecuteScriptResponse, error) {
if len(s.sessionID) == 0 {
return nil, newSessionIDError("ExecuteScript")
}
url := fmt.Sprintf("%s/session/%s/execute", s.seleniumURL, s.sessionID)
return s.scriptRequest(script, url, "ExecuteScript")
}
func (s *seleniumWebDriver) ExecuteScriptAsync(script string) (*ExecuteScriptResponse, error) {
if len(s.sessionID) == 0 {
return nil, newSessionIDError("ExecuteScriptAsync")
}
url := fmt.Sprintf("%s/session/%s/execute_async", s.seleniumURL, s.sessionID)
return s.scriptRequest(script, url, "ExecuteScriptAsync")
}