forked from abourget/agouti
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectable.go
More file actions
162 lines (136 loc) · 5.75 KB
/
selectable.go
File metadata and controls
162 lines (136 loc) · 5.75 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package agouti
import (
"github.com/sclevine/agouti/api"
"github.com/sclevine/agouti/internal/element"
"github.com/sclevine/agouti/internal/target"
)
type Selectors interface {
String() string
}
type selectable struct {
session apiSession
selectors target.Selectors
}
type apiSession interface {
element.Client
Delete() error
GetActiveElement() (*api.Element, error)
GetWindow() (*api.Window, error)
GetWindows() ([]*api.Window, error)
SetWindow(window *api.Window) error
SetWindowByName(name string) error
DeleteWindow() error
GetScreenshot() ([]byte, error)
GetCookies() ([]*api.Cookie, error)
SetCookie(cookie *api.Cookie) error
DeleteCookie(name string) error
DeleteCookies() error
GetURL() (string, error)
SetURL(url string) error
GetTitle() (string, error)
GetSource() (string, error)
DoubleClick() error
MoveTo(element *api.Element, point api.Offset) error
Frame(frame *api.Element) error
FrameParent() error
Execute(body string, arguments []interface{}, result interface{}) error
Forward() error
Back() error
Refresh() error
GetAlertText() (string, error)
SetAlertText(text string) error
AcceptAlert() error
DismissAlert() error
NewLogs(logType string) ([]api.Log, error)
GetLogTypes() ([]string, error)
}
// Find finds exactly one element by CSS selector.
func (s *selectable) Find(selector string) *Selection {
return newSelection(s.session, s.selectors.Append(target.CSS, selector).Single())
}
// FindByXPath finds exactly one element by XPath selector.
func (s *selectable) FindByXPath(selector string) *Selection {
return newSelection(s.session, s.selectors.Append(target.XPath, selector).Single())
}
// FindByLink finds exactly one anchor element by its text content.
func (s *selectable) FindByLink(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Link, text).Single())
}
// FindByLabel finds exactly one element by associated label text.
func (s *selectable) FindByLabel(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Label, text).Single())
}
// FindByButton finds exactly one button element with the provided text.
// Supports <button>, <input type="button">, and <input type="submit">.
func (s *selectable) FindByButton(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Button, text).Single())
}
// FindByClass finds exactly one element with a given CSS class.
func (s *selectable) FindByClass(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Class, text).Single())
}
// FindByID finds exactly one element that has the given ID.
func (s *selectable) FindByID(id string) *Selection {
return newSelection(s.session, s.selectors.Append(target.ID, id).Single())
}
// First finds the first element by CSS selector.
func (s *selectable) First(selector string) *Selection {
return newSelection(s.session, s.selectors.Append(target.CSS, selector).At(0))
}
// FirstByXPath finds the first element by XPath selector.
func (s *selectable) FirstByXPath(selector string) *Selection {
return newSelection(s.session, s.selectors.Append(target.XPath, selector).At(0))
}
// FirstByLink finds the first anchor element by its text content.
func (s *selectable) FirstByLink(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Link, text).At(0))
}
// FirstByLabel finds the first element by associated label text.
func (s *selectable) FirstByLabel(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Label, text).At(0))
}
// FirstByButton finds the first button element with the provided text.
// Supports <button>, <input type="button">, and <input type="submit">.
func (s *selectable) FirstByButton(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Button, text).At(0))
}
// FirstByClass finds the first element with a given CSS class.
func (s *selectable) FirstByClass(text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Class, text).At(0))
}
// All finds zero or more elements by CSS selector.
func (s *selectable) All(selector string) *MultiSelection {
return newMultiSelection(s.session, s.selectors.Append(target.CSS, selector))
}
// AllByXPath finds zero or more elements by XPath selector.
func (s *selectable) AllByXPath(selector string) *MultiSelection {
return newMultiSelection(s.session, s.selectors.Append(target.XPath, selector))
}
// AllByLink finds zero or more anchor elements by their text content.
func (s *selectable) AllByLink(text string) *MultiSelection {
return newMultiSelection(s.session, s.selectors.Append(target.Link, text))
}
// AllByLabel finds zero or more elements by associated label text.
func (s *selectable) AllByLabel(text string) *MultiSelection {
return newMultiSelection(s.session, s.selectors.Append(target.Label, text))
}
// AllByButton finds zero or more button elements with the provided text.
// Supports <button>, <input type="button">, and <input type="submit">.
func (s *selectable) AllByButton(text string) *MultiSelection {
return newMultiSelection(s.session, s.selectors.Append(target.Button, text))
}
// AllByClass finds zero or more elements with a given CSS class.
func (s *selectable) AllByClass(text string) *MultiSelection {
return newMultiSelection(s.session, s.selectors.Append(target.Class, text))
}
// AllByID finds zero or more elements with a given ID.
func (s *selectable) AllByID(text string) *MultiSelection {
return newMultiSelection(s.session, s.selectors.Append(target.ID, text))
}
// FirstByClass finds the first element with a given CSS class.
func (s *selectable) FindForAppium(selectorType string, text string) *Selection {
return newSelection(s.session, s.selectors.Append(target.Class, text).At(0))
}
func (s *selectable) Selectors() Selectors {
return s.selectors
}