-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwebelement.go
139 lines (109 loc) · 2.56 KB
/
webelement.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package marionette_client
import (
"encoding/json"
"fmt"
)
type Point struct {
X float32
Y float32
}
type Size struct {
Width float64
Height float64
}
type WindowRect struct {
X float64
Y float64
Width float64
Height float64
}
type ElementRect struct {
Point
Size
}
type WebElement struct {
id string //`json:"element-6066-11e4-a52e-4f735466cecf"`
c *Client
}
func (e *WebElement) Id() string {
return e.id
}
func (e *WebElement) GetActiveElement() (*WebElement, error) {
return getActiveElement(e.c)
}
func (e *WebElement) FindElement(by By, value string) (*WebElement, error) {
return findElement(e.c, by, value, &e.id)
}
func (e *WebElement) FindElements(by By, value string) ([]*WebElement, error) {
return findElements(e.c, by, value, &e.id)
}
func (e *WebElement) Enabled() bool {
return isElementEnabled(e.c, e.id)
}
func (e *WebElement) Selected() bool {
return isElementSelected(e.c, e.id)
}
func (e *WebElement) Displayed() bool {
return isElementDisplayed(e.c, e.id)
}
func (e *WebElement) TagName() string {
return getElementTagName(e.c, e.id)
}
func (e *WebElement) Text() string {
return getElementText(e.c, e.id)
}
func (e *WebElement) Attribute(name string) string {
return getElementAttribute(e.c, e.id, name)
}
func (e *WebElement) Property(name string) string {
return getElementProperty(e.c, e.id, name)
}
func (e *WebElement) CssValue(property string) string {
return getElementCssPropertyValue(e.c, e.id, property)
}
func (e *WebElement) Rect() (*ElementRect, error) {
return getElementRect(e.c, e.id)
}
func (e *WebElement) Click() {
clickElement(e.c, e.id)
}
func (e *WebElement) SendKeys(keys string) error {
return sendKeysToElement(e.c, e.id, keys)
}
func (e *WebElement) Clear() {
clearElement(e.c, e.id)
}
func (e *WebElement) Location() (*Point, error) {
r, err := getElementRect(e.c, e.id)
if err != nil {
return nil, err
}
return &r.Point, nil
}
func (e *WebElement) Size() (*Size, error) {
r, err := getElementRect(e.c, e.id)
if err != nil {
return nil, err
}
return &r.Size, nil
}
func (e *WebElement) Screenshot() (string, error) {
id := e.Id()
return takeScreenshot(e.c, &id)
}
func (e *WebElement) UnmarshalJSON(data []byte) error {
var d map[string]map[string]string
err := json.Unmarshal(data, &d)
if err != nil {
return err
}
if newId, ok := d["value"][WEBDRIVER_ELEMENT_KEY]; ok {
e.id = newId
return nil
}
return DriverError{
ErrorType: "WebDriverElementKey",
Message: fmt.Sprintf("key %v expected in response but not found", WEBDRIVER_ELEMENT_KEY),
Stacktrace: nil,
}
}