-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclickable.py
261 lines (197 loc) · 8.12 KB
/
clickable.py
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Definition of HTML elements: clickables, form and input field
"""
import dom_analyzer
import logging
class Clickable:
def __init__(self, clickable_id=None, clickable_name=None, xpath=None, tag=None):
self._id = clickable_id
self._name = clickable_name
self._xpath = xpath
self._tag = tag
#self._forms = []
def get_id(self):
return self._id
def get_name(self):
return self._name
def get_xpath(self):
return self._xpath
def get_tag(self):
return self._tag
def get_copy(self):
return Clickable(self._id, self._name, self._xpath, self._tag)
def __str__(self):
return 'clickable id: %s (xpath: %s) ' % (self._id, self._xpath )
class InputField:
def __init__(self, input_id=None, input_name=None, xpath=None, input_type=None, value=None):
self._id = input_id
self._name = input_name
self._xpath = xpath
self._value = value
self._type = input_type
self._mutation_info = None
def set_value(self, text):
self._value = text
def get_value(self):
return self._value
def get_id(self):
return self._id
def get_name(self):
return self._name
def get_xpath(self):
return self._xpath
def get_type(self):
return self._type
def set_mutation_info(self, info):
self._mutation_info = info
def get_mutation_info(self):
return self._mutation_info
def get_data_set(self, databank):
if not self._id.startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data(self._type, self._id)
elif not self._name.startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data(self._type, self._name)
else:
data_set = databank.get_data(self._type, 'None')
return data_set
def get_mutation_data_set(self, databank, modes):
mutation_type = self._type if self._type else 'text'
mutation_attr = self._id if not self._id.startswith(dom_analyzer.DomAnalyzer.serial_prefix) \
else self._name if not self._name.startswith(dom_analyzer.DomAnalyzer.serial_prefix) \
else 'None'
data_set = databank.get_mutation_data_set(mutation_type, mutation_attr, modes)
return data_set
def get_copy(self):
return InputField(self._id, self._name, self._xpath, self._type, self._value)
def __str__(self):
return 'input id: %s (xpath: %s), type: %s, value: %s' % (self._id, self._xpath, self._type, self._value)
#=============================================================================================
#Diff: select, checkbox, radio is an input, too.
class SelectField:
def __init__(self, select_id=None, select_name=None, xpath=None, value=None, selected=None):
self._id = select_id
self._name = select_name
self._xpath = xpath
self._value = value
self._selected = selected
#this value is list type
def get_value(self):
return self._value
def get_id(self):
return self._id
def get_name(self):
return self._name
def get_xpath(self):
return self._xpath
def set_selected(self, selected):
self._selected = selected
def get_selected(self):
return self._selected
def get_data_set(self, databank ):
if not self._id.startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data('select', self._id)
elif not self._name.startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data('select', self._name)
else:
data_set = databank.get_data('select', 'None')
return data_set
def get_copy(self):
return SelectField(self._id, self._name, self._xpath,
[ v for v in self._value ], self._selected)
def __str__(self):
return 'select id: %s (xpath: %s), value: %s' % (self._id, self._xpath, self._value)
class Checkbox:
def __init__(self, checkbox_id=None, checkbox_name=None, xpath=None, value=None):
self._id = checkbox_id
self._name = checkbox_name
self._xpath = xpath
self._value = value
def get_id(self):
return self._id
def get_name(self):
return self._name
def get_xpath(self):
return self._xpath
def set_value(self, value):
self._value = value
def get_value(self):
return self._value
def get_copy(self):
return Checkbox(self._id, self._name, self._xpath, self._value)
def __str__(self):
return 'checkbox id: %s, name: %s, (xpath: %s), value: %s' % (self._id, self._name, self._xpath, self._value)
class CheckboxField:
def __init__(self, checkbox_list=None, checkbox_name=None, checkbox_selected_list=None):
self._checkbox_list = checkbox_list
self._checkbox_name = checkbox_name
self._checkbox_selected_list = checkbox_selected_list
def set_selected_list(self, selected_list):
self._checkbox_selected_list = selected_list
def get_selected_list(self):
return self._checkbox_selected_list
def get_checkbox_list(self):
return self._checkbox_list
def get_checkbox_by_id(self, list_id):
return self._checkbox_list[list_id] if len(self._checkbox_list) >= list_id else None
def get_checkbox_name(self):
return self._checkbox_name
def get_data_set(self, databank):
if not self._checkbox_name.startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data('checkbox', self._checkbox_name)
elif not self._checkbox_list[0].get_id().startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data('checkbox', self._checkbox_list[0].get_id())
else:
data_set = databank.get_data('checkbox', 'None')
return data_set
def get_copy(self):
return CheckboxField([ c.get_copy() for c in self._checkbox_list ],
self._checkbox_name, self._checkbox_selected_list)
class Radio:
def __init__(self, radio_id=None, radio_name=None, xpath=None, value=None):
self._id = radio_id
self._name = radio_name
self._xpath = xpath
self._value = value
def get_id(self):
return self._id
def get_name(self):
return self._name
def get_xpath(self):
return self._xpath
def set_value(self, value):
self._value = value
def get_value(self):
return self._value
def get_copy(self):
return Radio(self._id, self._name, self._xpath, self._value)
def __str__(self):
return 'radio id: %s, name: %s, (xpath: %s), value: %s' % (self._id, self._name, self._xpath, self._value)
class RadioField:
def __init__(self, radio_list, radio_name=None, radio_selected=None):
self._radio_list = radio_list
self._radio_name = radio_name
self._radio_selected = radio_selected
def set_selected(self, selected):
self._radio_selected = selected
def get_selected(self):
return self._radio_selected
def get_radio_list(self):
return self._radio_list
def get_radio_by_id(self, list_id):
return self._radio_list[list_id] if len(self._radio_list) >= list_id else None
def get_radio_name(self):
return self._radio_name
def get_data_set(self, databank):
if not self._radio_name.startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data('radio', self._radio_name)
elif not self._radio_list[0].get_id().startswith(dom_analyzer.DomAnalyzer.serial_prefix):
data_set = databank.get_data('radio', self._radio_list[0].get_id())
else:
data_set = databank.get_data('radio', 'None')
return data_set
def get_copy(self):
return RadioField([ r.get_copy() for r in self._radio_list ],
self._radio_name, self._radio_selected)
#=============================================================================================