forked from bunsenapp/go-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_driver_document.go
68 lines (53 loc) · 1.61 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
60
61
62
63
64
65
66
67
68
package goselenium
import (
"encoding/json"
"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
}
var value string
err = json.Unmarshal(resp.Value, &value)
if err != nil {
return nil, newUnmarshallingError(err, "PageSource", string(resp.Value))
}
return &PageSourceResponse{State: resp.State, Source: 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")
}