robo_appian 0.0.10__py3-none-any.whl → 0.0.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of robo_appian might be problematic. Click here for more details.
- robo_appian/components/ButtonUtils.py +20 -42
- robo_appian/components/DateUtils.py +43 -111
- robo_appian/components/DropdownUtils.py +203 -136
- robo_appian/components/InputUtils.py +83 -47
- robo_appian/components/LabelUtils.py +22 -30
- robo_appian/components/LinkUtils.py +9 -9
- robo_appian/components/SearchDropdownUtils.py +75 -0
- robo_appian/components/SearchInputUtils.py +23 -28
- robo_appian/components/TabUtils.py +24 -29
- robo_appian/components/TableUtils.py +42 -77
- robo_appian/controllers/ComponentDriver.py +7 -10
- robo_appian/utils/ComponentUtils.py +6 -3
- {robo_appian-0.0.10.dist-info → robo_appian-0.0.12.dist-info}/METADATA +1 -1
- robo_appian-0.0.12.dist-info/RECORD +22 -0
- robo_appian-0.0.10.dist-info/RECORD +0 -21
- {robo_appian-0.0.10.dist-info → robo_appian-0.0.12.dist-info}/LICENSE +0 -0
- {robo_appian-0.0.10.dist-info → robo_appian-0.0.12.dist-info}/WHEEL +0 -0
|
@@ -2,176 +2,243 @@ from selenium.webdriver.common.by import By
|
|
|
2
2
|
from selenium.webdriver.support import expected_conditions as EC
|
|
3
3
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
4
4
|
from selenium.webdriver.remote.webelement import WebElement
|
|
5
|
-
|
|
6
|
-
from robo_appian.components.InputUtils import InputUtils
|
|
5
|
+
from selenium.common.exceptions import NoSuchElementException
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
class DropdownUtils:
|
|
10
9
|
"""
|
|
11
10
|
Utility class for interacting with dropdown components in Appian UI.
|
|
12
|
-
|
|
13
|
-
Usage Example:
|
|
14
|
-
|
|
11
|
+
Usage Example:
|
|
15
12
|
# Select a value from a dropdown
|
|
16
13
|
from robo_appian.components.DropdownUtils import DropdownUtils
|
|
17
14
|
DropdownUtils.selectDropdownValueByLabelText(wait, "Status", "Approved")
|
|
18
|
-
|
|
19
|
-
# Select a value from a search dropdown
|
|
20
|
-
from robo_appian.components.DropdownUtils import DropdownUtils
|
|
21
|
-
DropdownUtils.selectSearchDropdownValueByLabelText(wait, "Category", "Finance")
|
|
22
15
|
"""
|
|
23
16
|
|
|
24
17
|
@staticmethod
|
|
25
|
-
def
|
|
18
|
+
def __findComboboxByPartialLabelText(wait: WebDriverWait, label: str):
|
|
19
|
+
"""
|
|
20
|
+
Finds a combobox by its partial label text.
|
|
21
|
+
|
|
22
|
+
:param wait: Selenium WebDriverWait instance.
|
|
23
|
+
:param label: The partial label of the combobox to find.
|
|
24
|
+
:return: WebElement representing the combobox.
|
|
25
|
+
Example:
|
|
26
|
+
component = DropdownUtils.__findComboboxByPartialLabelText(wait, "Dropdown Label")
|
|
27
|
+
"""
|
|
28
|
+
xpath = f'.//div[./div/span[contains(normalize-space(text()), "{label}")]]/div/div/div/div[@role="combobox" and not(@aria-disabled="true")]' # noqa: E501
|
|
26
29
|
try:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
except TimeoutError as e:
|
|
31
|
-
raise TimeoutError(
|
|
32
|
-
f'No clickable dropdown component found for xpath "{xpath}": {str(e)}'
|
|
33
|
-
)
|
|
34
|
-
except Exception as e:
|
|
35
|
-
raise Exception(
|
|
36
|
-
f'No clickable dropdown component found for xpath "{xpath}": {str(e)}'
|
|
37
|
-
)
|
|
30
|
+
component = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
31
|
+
except Exception as e:
|
|
32
|
+
raise Exception(f'Could not find combobox with partial label "{label}" : {str(e)}')
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
driver = wait._driver
|
|
41
|
-
components = driver.find_elements(By.XPATH, xpath)
|
|
34
|
+
return component
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
@staticmethod
|
|
37
|
+
def __findComboboxByLabelText(wait: WebDriverWait, label: str):
|
|
38
|
+
"""
|
|
39
|
+
Finds a combobox by its label text.
|
|
40
|
+
|
|
41
|
+
:param wait: Selenium WebDriverWait instance.
|
|
42
|
+
:param label: The label of the combobox to find.
|
|
43
|
+
:return: WebElement representing the combobox.
|
|
44
|
+
Example:
|
|
45
|
+
component = DropdownUtils.__findComboboxByLabelText(wait, "Dropdown Label")
|
|
46
|
+
"""
|
|
47
|
+
xpath = f'.//div[./div/span[normalize-space(text())="{label}"]]/div/div/div/div[@role="combobox" and not(@aria-disabled="true")]' # noqa: E501
|
|
48
|
+
try:
|
|
49
|
+
component = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
50
|
+
except Exception as e:
|
|
51
|
+
raise Exception(f'Could not find combobox with label "{label}" : {str(e)}')
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
raise Exception(
|
|
54
|
-
f'No valid dropdown components with xpath "{xpath}" found.'
|
|
55
|
-
)
|
|
53
|
+
return component
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
@staticmethod
|
|
56
|
+
def __clickCombobox(wait: WebDriverWait, combobox: WebElement):
|
|
57
|
+
"""
|
|
58
|
+
Clicks the combobox to open the dropdown options.
|
|
59
|
+
|
|
60
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
61
|
+
:param combobox: The combobox WebElement.
|
|
62
|
+
Example:
|
|
63
|
+
DropdownUtils.__clickCombobox(wait, combobox)
|
|
64
|
+
"""
|
|
65
|
+
combobox.click()
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
@staticmethod
|
|
68
|
+
def __findDropdownOptionId(wait: WebDriverWait, combobox: WebElement):
|
|
69
|
+
"""
|
|
70
|
+
Finds the dropdown option id from the combobox.
|
|
71
|
+
|
|
72
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
73
|
+
:param combobox: The combobox WebElement.
|
|
74
|
+
:return: The id of the dropdown options list.
|
|
75
|
+
Example:
|
|
76
|
+
dropdown_option_id = DropdownUtils.__findDropdownOptionId(wait, combobox)
|
|
77
|
+
"""
|
|
78
|
+
dropdown_option_id = combobox.get_attribute("aria-controls")
|
|
79
|
+
if dropdown_option_id is None:
|
|
80
|
+
raise Exception('Dropdown component does not have a valid "aria-controls" attribute.')
|
|
81
|
+
return dropdown_option_id
|
|
64
82
|
|
|
65
83
|
@staticmethod
|
|
66
|
-
def
|
|
67
|
-
|
|
68
|
-
|
|
84
|
+
def __checkDropdownOptionValueExistsByDropdownOptionId(wait: WebDriverWait, dropdown_option_id: str, value: str):
|
|
85
|
+
"""
|
|
86
|
+
Checks if a dropdown option value exists by its option id and value.
|
|
87
|
+
|
|
88
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
89
|
+
:param dropdown_option_id: The id of the dropdown options list.
|
|
90
|
+
:param value: The value to check in the dropdown.
|
|
91
|
+
Example:
|
|
92
|
+
exists = DropdownUtils.checkDropdownOptionValueExistsByDropdownOptionId(wait, "dropdown_option_id", "Option Value")
|
|
93
|
+
if exists:
|
|
94
|
+
print("The value exists in the dropdown.")
|
|
95
|
+
else:
|
|
96
|
+
print("The value does not exist in the dropdown.")
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
xpath = f'.//div/ul[@id="{dropdown_option_id}"]/li[./div[normalize-space(text())="{value}"]]'
|
|
100
|
+
try:
|
|
101
|
+
wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
102
|
+
return True
|
|
103
|
+
except NoSuchElementException:
|
|
104
|
+
return False
|
|
105
|
+
except Exception as e:
|
|
106
|
+
raise Exception(f'Could not find dropdown option "{value}" with dropdown option id "{dropdown_option_id}": {str(e)}')
|
|
69
107
|
|
|
70
|
-
|
|
108
|
+
@staticmethod
|
|
109
|
+
def __selectDropdownValueByDropdownOptionId(wait: WebDriverWait, dropdown_option_id: str, value: str):
|
|
110
|
+
"""
|
|
111
|
+
Selects a value from a dropdown by its option id and value.
|
|
112
|
+
|
|
113
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
114
|
+
:param dropdown_option_id: The id of the dropdown options list.
|
|
115
|
+
:param value: The value to select from the dropdown.
|
|
116
|
+
Example:
|
|
117
|
+
DropdownUtils.selectDropdownValueByDropdownOptionId(wait, "dropdown_option_id", "Option Value")
|
|
118
|
+
"""
|
|
119
|
+
option_xpath = f'.//div/ul[@id="{dropdown_option_id}"]/li[./div[normalize-space(text())="{value}"]]'
|
|
71
120
|
try:
|
|
72
|
-
|
|
73
|
-
EC.presence_of_element_located((By.XPATH, option_xpath))
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)
|
|
121
|
+
try:
|
|
122
|
+
component = wait.until(EC.presence_of_element_located((By.XPATH, option_xpath)))
|
|
123
|
+
component = wait.until(EC.element_to_be_clickable((By.XPATH, option_xpath)))
|
|
124
|
+
except Exception as e:
|
|
125
|
+
raise Exception(
|
|
126
|
+
f'Could not locate or click dropdown option "{value}" with dropdown option id "{dropdown_option_id}": {str(e)}' # noqa: E501
|
|
127
|
+
)
|
|
80
128
|
except Exception as e:
|
|
81
|
-
raise Exception(
|
|
82
|
-
f'Could not find or click dropdown option "{value}" with xpath "{option_xpath}": {str(e)}'
|
|
83
|
-
)
|
|
129
|
+
raise Exception(f'Could not find or click dropdown option "{value}" with xpath "{option_xpath}": {str(e)}')
|
|
84
130
|
component.click()
|
|
85
131
|
|
|
86
132
|
@staticmethod
|
|
87
|
-
def
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
133
|
+
def __selectDropdownValueByPartialLabelText(wait: WebDriverWait, label: str, value: str):
|
|
134
|
+
"""
|
|
135
|
+
Selects a value from a dropdown by its label text.
|
|
136
|
+
|
|
137
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
138
|
+
:param label: The label of the dropdown.
|
|
139
|
+
:param value: The value to select from the dropdown.
|
|
140
|
+
"""
|
|
141
|
+
combobox = DropdownUtils.__findComboboxByPartialLabelText(wait, label)
|
|
142
|
+
DropdownUtils.__clickCombobox(wait, combobox)
|
|
143
|
+
dropdown_option_id = DropdownUtils.__findDropdownOptionId(wait, combobox)
|
|
144
|
+
DropdownUtils.__selectDropdownValueByDropdownOptionId(wait, dropdown_option_id, value)
|
|
92
145
|
|
|
93
146
|
@staticmethod
|
|
94
|
-
def
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
147
|
+
def __selectDropdownValueByLabelText(wait: WebDriverWait, label: str, value: str):
|
|
148
|
+
"""
|
|
149
|
+
Selects a value from a dropdown by its label text.
|
|
150
|
+
|
|
151
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
152
|
+
:param label: The label of the dropdown.
|
|
153
|
+
:param value: The value to select from the dropdown.
|
|
154
|
+
"""
|
|
155
|
+
combobox = DropdownUtils.__findComboboxByLabelText(wait, label)
|
|
156
|
+
DropdownUtils.__clickCombobox(wait, combobox)
|
|
157
|
+
dropdown_option_id = DropdownUtils.__findDropdownOptionId(wait, combobox)
|
|
158
|
+
DropdownUtils.__selectDropdownValueByDropdownOptionId(wait, dropdown_option_id, value)
|
|
99
159
|
|
|
100
160
|
@staticmethod
|
|
101
|
-
def
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
161
|
+
def checkReadOnlyStatusByLabelText(wait: WebDriverWait, label: str):
|
|
162
|
+
"""
|
|
163
|
+
Checks if a dropdown is read-only by its label text.
|
|
164
|
+
|
|
165
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
166
|
+
:param label: The label of the dropdown.
|
|
167
|
+
:return: True if the dropdown is read-only, False otherwise.
|
|
168
|
+
Example:
|
|
169
|
+
is_read_only = DropdownUtils.checkReadOnlyStatusByLabelText(wait, "Dropdown Label")
|
|
170
|
+
if is_read_only:
|
|
171
|
+
print("The dropdown is read-only.")
|
|
172
|
+
else:
|
|
173
|
+
print("The dropdown is editable.")
|
|
174
|
+
"""
|
|
175
|
+
xpath = f'.//div[./div/span[normalize-space(text())="{label}"]]/div/div/p[text()]'
|
|
176
|
+
try:
|
|
177
|
+
wait._driver.find_element(By.XPATH, xpath)
|
|
178
|
+
return True
|
|
179
|
+
except NoSuchElementException:
|
|
180
|
+
return False
|
|
181
|
+
except Exception:
|
|
182
|
+
raise Exception(f'Error checking read-only status for label "{label}"')
|
|
106
183
|
|
|
107
184
|
@staticmethod
|
|
108
|
-
def
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
except TimeoutError as e:
|
|
123
|
-
raise TimeoutError(
|
|
124
|
-
f'Could not find or click search input component with id "{input_component_id}": {str(e)}'
|
|
125
|
-
)
|
|
126
|
-
except Exception as e:
|
|
127
|
-
raise Exception(
|
|
128
|
-
f'Could not find or click search input component with id "{input_component_id}": {str(e)}'
|
|
129
|
-
)
|
|
130
|
-
InputUtils._setComponentValue(input_component, value)
|
|
131
|
-
|
|
132
|
-
xpath = f'.//ul[@id="{dropdown_id}"]/li[./div[normalize-space(text())="{value}"]][1]'
|
|
133
|
-
try:
|
|
134
|
-
component = wait.until(
|
|
135
|
-
EC.element_to_be_clickable((By.XPATH, xpath))
|
|
136
|
-
)
|
|
137
|
-
except TimeoutError as e:
|
|
138
|
-
raise TimeoutError(
|
|
139
|
-
f'Could not find or click search dropdown option "{value}" with xpath "{xpath}": {str(e)}'
|
|
140
|
-
)
|
|
141
|
-
except Exception as e:
|
|
142
|
-
raise Exception(
|
|
143
|
-
f'Could not find or click search dropdown option "{value}" with xpath "{xpath}": {str(e)}'
|
|
144
|
-
)
|
|
145
|
-
component.click()
|
|
185
|
+
def selectDropdownValueByComboboxComponent(wait: WebDriverWait, combobox: WebElement, value: str):
|
|
186
|
+
"""
|
|
187
|
+
Selects a value from a dropdown using the combobox component.
|
|
188
|
+
|
|
189
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
190
|
+
:param combobox: The combobox WebElement.
|
|
191
|
+
:param value: The value to select from the dropdown.
|
|
192
|
+
Example:
|
|
193
|
+
DropdownUtils.selectDropdownValueByComboboxComponent(wait, combobox, "Option Value")
|
|
194
|
+
"""
|
|
195
|
+
dropdown_option_id = DropdownUtils.__findDropdownOptionId(wait, combobox)
|
|
196
|
+
DropdownUtils.__clickCombobox(wait, combobox)
|
|
197
|
+
DropdownUtils.__selectDropdownValueByDropdownOptionId(wait, dropdown_option_id, value)
|
|
146
198
|
|
|
147
199
|
@staticmethod
|
|
148
|
-
def
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
200
|
+
def selectDropdownValueByLabelText(wait: WebDriverWait, dropdown_label: str, value: str):
|
|
201
|
+
"""
|
|
202
|
+
Selects a value from a dropdown by its label text.
|
|
203
|
+
|
|
204
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
205
|
+
:param dropdown_label: The label of the dropdown.
|
|
206
|
+
:param value: The value to select from the dropdown.
|
|
207
|
+
Example:
|
|
208
|
+
DropdownUtils.selectDropdownValueByLabelText(wait, "Dropdown Label", "Option Value")
|
|
209
|
+
"""
|
|
210
|
+
DropdownUtils.__selectDropdownValueByLabelText(wait, dropdown_label, value)
|
|
153
211
|
|
|
154
212
|
@staticmethod
|
|
155
|
-
def
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
213
|
+
def selectDropdownValueByPartialLabelText(wait: WebDriverWait, dropdown_label: str, value: str):
|
|
214
|
+
"""
|
|
215
|
+
Selects a value from a dropdown by its partial label text.
|
|
216
|
+
|
|
217
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
218
|
+
:param dropdown_label: The partial label of the dropdown.
|
|
219
|
+
:param value: The value to select from the dropdown.
|
|
220
|
+
Example:
|
|
221
|
+
DropdownUtils.selectDropdownValueByPartialLabelText(wait, "Dropdown Label", "Option Value")
|
|
222
|
+
"""
|
|
223
|
+
DropdownUtils.__selectDropdownValueByPartialLabelText(wait, dropdown_label, value)
|
|
160
224
|
|
|
161
225
|
@staticmethod
|
|
162
|
-
def
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
226
|
+
def checkDropdownOptionValueExists(wait: WebDriverWait, dropdown_label: str, value: str):
|
|
227
|
+
"""
|
|
228
|
+
Checks if a dropdown option value exists by its label text.
|
|
229
|
+
|
|
230
|
+
:param wait: WebDriverWait instance to wait for elements.
|
|
231
|
+
:param dropdown_label: The label of the dropdown.
|
|
232
|
+
:param value: The value to check in the dropdown.
|
|
233
|
+
:return: True if the value exists, False otherwise.
|
|
234
|
+
Example:
|
|
235
|
+
exists = DropdownUtils.checkDropdownOptionValueExists(wait, "Dropdown Label", "Option Value")
|
|
236
|
+
if exists:
|
|
237
|
+
print("The value exists in the dropdown.")
|
|
238
|
+
else:
|
|
239
|
+
print("The value does not exist in the dropdown.")
|
|
240
|
+
"""
|
|
241
|
+
combobox = DropdownUtils.__findComboboxByLabelText(wait, dropdown_label)
|
|
242
|
+
DropdownUtils.__clickCombobox(wait, combobox)
|
|
243
|
+
dropdown_option_id = DropdownUtils.__findDropdownOptionId(wait, combobox)
|
|
244
|
+
return DropdownUtils.__checkDropdownOptionValueExistsByDropdownOptionId(wait, dropdown_option_id, value)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from robo_appian.utils.ComponentUtils import ComponentUtils
|
|
2
2
|
from selenium.webdriver.common.by import By
|
|
3
|
-
from selenium.webdriver.common.keys import Keys
|
|
4
3
|
from selenium.webdriver.support import expected_conditions as EC
|
|
5
4
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
6
5
|
from selenium.webdriver.remote.webelement import WebElement
|
|
@@ -9,44 +8,31 @@ from selenium.webdriver.remote.webelement import WebElement
|
|
|
9
8
|
class InputUtils:
|
|
10
9
|
"""
|
|
11
10
|
Utility class for interacting with input components in Appian UI.
|
|
12
|
-
|
|
13
|
-
Usage Example:
|
|
14
|
-
|
|
15
|
-
# Set a value in an input field
|
|
11
|
+
Usage Example:
|
|
16
12
|
from robo_appian.components.InputUtils import InputUtils
|
|
13
|
+
|
|
14
|
+
# Set a value in an input component by its label
|
|
17
15
|
InputUtils.setValueByLabelText(wait, "Username", "test_user")
|
|
18
16
|
|
|
17
|
+
# Set a value in an input component by its ID
|
|
18
|
+
InputUtils.setValueById(wait, "inputComponentId", "test_value")
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
21
|
@staticmethod
|
|
22
|
-
def
|
|
22
|
+
def __findInputComponentsByXpath(wait: WebDriverWait, xpath: str):
|
|
23
23
|
"""
|
|
24
|
-
|
|
24
|
+
Finds input components by their XPath.
|
|
25
25
|
|
|
26
26
|
Parameters:
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
wait: Selenium WebDriverWait instance.
|
|
28
|
+
xpath: The XPath expression to locate the input components.
|
|
29
29
|
|
|
30
30
|
Returns:
|
|
31
|
-
|
|
31
|
+
A list of Selenium WebElement representing the input components.
|
|
32
32
|
|
|
33
33
|
Example:
|
|
34
|
-
InputUtils.
|
|
35
|
-
|
|
34
|
+
InputUtils.__findInputComponentsByXpath(wait, './/div/label[normalize-space(text())="Username"]')
|
|
36
35
|
"""
|
|
37
|
-
# This method assumes that the component is already found and passed as an argument.
|
|
38
|
-
|
|
39
|
-
if not component.is_displayed():
|
|
40
|
-
raise Exception(
|
|
41
|
-
f"Component with label '{component.text}' is not displayed."
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
component = InputUtils._setComponentValue(component, value)
|
|
45
|
-
component.send_keys(Keys.ENTER)
|
|
46
|
-
return component
|
|
47
|
-
|
|
48
|
-
@staticmethod
|
|
49
|
-
def __findInputComponentsByXpath(wait: WebDriverWait, xpath: str):
|
|
50
36
|
label_components = ComponentUtils.findComponentsByXPath(wait, xpath)
|
|
51
37
|
input_components = []
|
|
52
38
|
for label_component in label_components:
|
|
@@ -54,34 +40,62 @@ class InputUtils:
|
|
|
54
40
|
component_id = label_component.get_attribute(attribute) # type: ignore[reportUnknownMemberType]
|
|
55
41
|
if component_id:
|
|
56
42
|
try:
|
|
57
|
-
component = wait.until(
|
|
58
|
-
EC.element_to_be_clickable((By.ID, component_id))
|
|
59
|
-
)
|
|
43
|
+
component = wait.until(EC.element_to_be_clickable((By.ID, component_id)))
|
|
60
44
|
input_components.append(component)
|
|
61
|
-
except TimeoutError as e:
|
|
62
|
-
raise TimeoutError(
|
|
63
|
-
f"Timeout or error finding input component with id '{component_id}': {e}"
|
|
64
|
-
)
|
|
65
45
|
except Exception as e:
|
|
66
|
-
raise Exception(
|
|
67
|
-
|
|
68
|
-
|
|
46
|
+
raise Exception(f"Could not find clickable input component with id '{component_id}': {e}")
|
|
47
|
+
else:
|
|
48
|
+
raise ValueError(f"Input component with label '{label_component.text}' does not have 'for' attribute.")
|
|
69
49
|
return input_components
|
|
70
50
|
|
|
71
51
|
@staticmethod
|
|
72
52
|
def __findInputComponentsByPartialLabel(wait: WebDriverWait, label: str):
|
|
53
|
+
"""Finds input components by their label text, allowing for partial matches.
|
|
54
|
+
|
|
55
|
+
Parameters:
|
|
56
|
+
wait: Selenium WebDriverWait instance.
|
|
57
|
+
label: The visible text label of the input component, allowing for partial matches.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
A list of Selenium WebElement representing the input components.
|
|
61
|
+
|
|
62
|
+
Example:
|
|
63
|
+
InputUtils.__findInputComponentsByPartialLabel(wait, "Username")
|
|
64
|
+
"""
|
|
73
65
|
xpath = f'.//div/label[contains(normalize-space(text()), "{label}")]'
|
|
74
66
|
components = InputUtils.__findInputComponentsByXpath(wait, xpath)
|
|
75
67
|
return components
|
|
76
68
|
|
|
77
69
|
@staticmethod
|
|
78
|
-
def
|
|
70
|
+
def __findComponentsByLabel(wait: WebDriverWait, label: str):
|
|
71
|
+
"""Finds input components by their label text.
|
|
72
|
+
|
|
73
|
+
Parameters:
|
|
74
|
+
wait: Selenium WebDriverWait instance.
|
|
75
|
+
label: The visible text label of the input component.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
A list of Selenium WebElement representing the input components.
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
InputUtils.__findComponentsByLabel(wait, "Username")
|
|
82
|
+
"""
|
|
79
83
|
xpath = f'.//div/label[normalize-space(text())="{label}"]'
|
|
80
84
|
components = InputUtils.__findInputComponentsByXpath(wait, xpath)
|
|
81
85
|
return components
|
|
82
86
|
|
|
83
87
|
@staticmethod
|
|
84
|
-
def
|
|
88
|
+
def _setValueByComponent(component: WebElement, value: str):
|
|
89
|
+
"""
|
|
90
|
+
Sets a value in an input component.
|
|
91
|
+
Parameters:
|
|
92
|
+
component: The Selenium WebElement for the input component.
|
|
93
|
+
value: The value to set in the input field.
|
|
94
|
+
Returns:
|
|
95
|
+
The Selenium WebElement for the input component after setting the value.
|
|
96
|
+
Example:
|
|
97
|
+
InputUtils._setValueByComponent(component, "test_value")
|
|
98
|
+
"""
|
|
85
99
|
component.clear()
|
|
86
100
|
component.send_keys(value)
|
|
87
101
|
return component
|
|
@@ -101,7 +115,7 @@ class InputUtils:
|
|
|
101
115
|
"""
|
|
102
116
|
|
|
103
117
|
for component in input_components:
|
|
104
|
-
InputUtils.
|
|
118
|
+
InputUtils._setValueByComponent(component, value)
|
|
105
119
|
|
|
106
120
|
@staticmethod
|
|
107
121
|
def setValueByPartialLabelText(wait: WebDriverWait, label: str, value: str):
|
|
@@ -110,20 +124,42 @@ class InputUtils:
|
|
|
110
124
|
|
|
111
125
|
@staticmethod
|
|
112
126
|
def setValueByLabelText(wait: WebDriverWait, label: str, value: str):
|
|
113
|
-
|
|
127
|
+
"""
|
|
128
|
+
Sets a value in an input component identified by its label text.
|
|
129
|
+
|
|
130
|
+
Parameters:
|
|
131
|
+
wait: Selenium WebDriverWait instance.
|
|
132
|
+
label: The visible text label of the input component.
|
|
133
|
+
value: The value to set in the input field.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
None
|
|
137
|
+
|
|
138
|
+
Example:
|
|
139
|
+
InputUtils.setValueByLabelText(wait, "Username", "test_user")
|
|
140
|
+
"""
|
|
141
|
+
input_components = InputUtils.__findComponentsByLabel(wait, label)
|
|
114
142
|
InputUtils.__setValueByComponents(wait, input_components, value)
|
|
115
143
|
|
|
116
144
|
@staticmethod
|
|
117
145
|
def setValueById(wait: WebDriverWait, component_id: str, value: str):
|
|
146
|
+
"""
|
|
147
|
+
Sets a value in an input component identified by its ID.
|
|
148
|
+
|
|
149
|
+
Parameters:
|
|
150
|
+
wait: Selenium WebDriverWait instance.
|
|
151
|
+
component_id: The ID of the input component.
|
|
152
|
+
value: The value to set in the input field.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
The Selenium WebElement for the input component after setting the value.
|
|
156
|
+
|
|
157
|
+
Example:
|
|
158
|
+
InputUtils.setValueById(wait, "inputComponentId", "test_value")
|
|
159
|
+
"""
|
|
118
160
|
try:
|
|
119
161
|
component = wait.until(EC.element_to_be_clickable((By.ID, component_id)))
|
|
120
|
-
except TimeoutError as e:
|
|
121
|
-
raise TimeoutError(
|
|
122
|
-
f"Timeout or error finding input component with id '{component_id}': {e}"
|
|
123
|
-
)
|
|
124
162
|
except Exception as e:
|
|
125
|
-
raise Exception(
|
|
126
|
-
|
|
127
|
-
)
|
|
128
|
-
InputUtils._setComponentValue(component, value)
|
|
163
|
+
raise Exception(f"Timeout or error finding input component with id '{component_id}': {e}")
|
|
164
|
+
InputUtils._setValueByComponent(component, value)
|
|
129
165
|
return component
|
|
@@ -6,49 +6,41 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|
|
6
6
|
class LabelUtils:
|
|
7
7
|
"""
|
|
8
8
|
Utility class for interacting with label components in Appian UI.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
label_component = LabelUtils.find(wait, "Username")
|
|
15
|
-
|
|
9
|
+
Usage Example:
|
|
10
|
+
# Find a label by its text
|
|
11
|
+
component = LabelUtils.findByLabelText(wait, "Submit")
|
|
12
|
+
# Click a label by its text
|
|
13
|
+
LabelUtils.clickByLabelText(wait, "Submit")
|
|
16
14
|
"""
|
|
17
15
|
|
|
18
16
|
@staticmethod
|
|
19
|
-
def
|
|
17
|
+
def findByLabelText(wait: WebDriverWait, label: str):
|
|
20
18
|
"""
|
|
21
|
-
Finds a label
|
|
22
|
-
|
|
23
|
-
Parameters:
|
|
24
|
-
wait: Selenium WebDriverWait instance.
|
|
25
|
-
label: The visible text label of the component.
|
|
26
|
-
|
|
27
|
-
Returns:
|
|
28
|
-
The Selenium WebElement for the label component.
|
|
19
|
+
Finds a label element by its text.
|
|
29
20
|
|
|
21
|
+
:param wait: Selenium WebDriverWait instance.
|
|
22
|
+
:param label: The text of the label to find.
|
|
23
|
+
:return: WebElement representing the label.
|
|
30
24
|
Example:
|
|
31
|
-
LabelUtils.
|
|
32
|
-
|
|
25
|
+
component = LabelUtils.findByLabelText(wait, "Submit")
|
|
33
26
|
"""
|
|
34
|
-
# This method locates a label component that contains the specified text.
|
|
35
|
-
# It uses XPath to find the element that matches the text.
|
|
36
|
-
|
|
37
27
|
xpath = f".//*[normalize-space(text())='{label}']"
|
|
38
28
|
try:
|
|
39
29
|
component = wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
|
|
40
|
-
except TimeoutError as e:
|
|
41
|
-
raise TimeoutError(
|
|
42
|
-
f"Label '{label}' not found within the timeout period."
|
|
43
|
-
) from e
|
|
44
30
|
except Exception as e:
|
|
45
|
-
raise
|
|
46
|
-
f"Label '{label}' not found within the timeout period."
|
|
47
|
-
) from e
|
|
31
|
+
raise RuntimeError(f"Label with text '{label}' not found.") from e
|
|
48
32
|
|
|
49
33
|
return component
|
|
50
34
|
|
|
51
35
|
@staticmethod
|
|
52
|
-
def
|
|
53
|
-
|
|
36
|
+
def clickByLabelText(wait: WebDriverWait, label: str):
|
|
37
|
+
"""
|
|
38
|
+
Clicks a label element identified by its text.
|
|
39
|
+
|
|
40
|
+
:param wait: Selenium WebDriverWait instance.
|
|
41
|
+
:param label: The text of the label to click.
|
|
42
|
+
Example:
|
|
43
|
+
LabelUtils.clickByLabelText(wait, "Submit")
|
|
44
|
+
"""
|
|
45
|
+
component = LabelUtils.findByLabelText(wait, label)
|
|
54
46
|
component.click()
|