robo_appian 0.0.11__py3-none-any.whl → 0.0.13__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 +64 -10
- robo_appian/components/DateUtils.py +43 -111
- robo_appian/components/DropdownUtils.py +117 -5
- 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 +1 -1
- 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 +4 -4
- robo_appian/utils/ComponentUtils.py +71 -112
- robo_appian-0.0.13.dist-info/METADATA +67 -0
- robo_appian-0.0.13.dist-info/RECORD +22 -0
- robo_appian-0.0.11.dist-info/METADATA +0 -140
- robo_appian-0.0.11.dist-info/RECORD +0 -22
- {robo_appian-0.0.11.dist-info → robo_appian-0.0.13.dist-info}/LICENSE +0 -0
- {robo_appian-0.0.11.dist-info → robo_appian-0.0.13.dist-info}/WHEEL +0 -0
|
@@ -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()
|
|
@@ -5,14 +5,16 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|
|
5
5
|
|
|
6
6
|
class LinkUtils:
|
|
7
7
|
"""
|
|
8
|
-
Utility class for
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# Click a link with a specific label
|
|
8
|
+
Utility class for handling link operations in Selenium WebDriver.
|
|
9
|
+
Example usage:
|
|
10
|
+
from selenium import webdriver
|
|
11
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
13
12
|
from robo_appian.components.LinkUtils import LinkUtils
|
|
14
|
-
LinkUtils.click(wait, "Learn More")
|
|
15
13
|
|
|
14
|
+
driver = webdriver.Chrome()
|
|
15
|
+
wait = WebDriverWait(driver, 10)
|
|
16
|
+
LinkUtils.click(wait, "Learn More")
|
|
17
|
+
driver.quit()
|
|
16
18
|
"""
|
|
17
19
|
|
|
18
20
|
@staticmethod
|
|
@@ -21,9 +23,7 @@ class LinkUtils:
|
|
|
21
23
|
try:
|
|
22
24
|
component = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
23
25
|
except TimeoutError as e:
|
|
24
|
-
raise TimeoutError(
|
|
25
|
-
f"Could not find clickable link with label '{label}': {e}"
|
|
26
|
-
)
|
|
26
|
+
raise TimeoutError(f"Could not find clickable link with label '{label}': {e}")
|
|
27
27
|
except Exception as e:
|
|
28
28
|
raise Exception(f"Could not find clickable link with label '{label}': {e}")
|
|
29
29
|
return component
|
|
@@ -20,7 +20,7 @@ class SearchDropdownUtils:
|
|
|
20
20
|
input_component = wait.until(EC.element_to_be_clickable((By.ID, input_component_id)))
|
|
21
21
|
except Exception as e:
|
|
22
22
|
raise RuntimeError(f"Failed to locate or click input component with ID '{input_component_id}': {e}")
|
|
23
|
-
InputUtils.
|
|
23
|
+
InputUtils._setValueByComponent(input_component, value)
|
|
24
24
|
|
|
25
25
|
xpath = f'.//ul[@id="{dropdown_option_id}"]/li[./div[normalize-space(text())="{value}"]][1]'
|
|
26
26
|
try:
|
|
@@ -6,22 +6,31 @@ from robo_appian.utils.ComponentUtils import ComponentUtils
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class SearchInputUtils:
|
|
9
|
+
"""
|
|
10
|
+
Utility class for handling search input operations in Selenium WebDriver.
|
|
11
|
+
Example usage:
|
|
12
|
+
from selenium import webdriver
|
|
13
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
14
|
+
from robo_appian.components.SearchInputUtils import SearchInputUtils
|
|
15
|
+
|
|
16
|
+
driver = webdriver.Chrome()
|
|
17
|
+
wait = WebDriverWait(driver, 10)
|
|
18
|
+
SearchInputUtils.selectSearchDropdownByLabelText(wait, "Search Label", "Value")
|
|
19
|
+
driver.quit()
|
|
20
|
+
"""
|
|
21
|
+
|
|
9
22
|
@staticmethod
|
|
10
|
-
def __findSearchInputComponentsByLabelPathAndSelectValue(
|
|
11
|
-
wait: WebDriverWait, xpath: str, value: str
|
|
12
|
-
):
|
|
23
|
+
def __findSearchInputComponentsByLabelPathAndSelectValue(wait: WebDriverWait, xpath: str, value: str):
|
|
13
24
|
search_input_components = ComponentUtils.findComponentsByXPath(wait, xpath)
|
|
14
25
|
input_components = []
|
|
15
26
|
for search_input_component in search_input_components:
|
|
16
27
|
attribute: str = "aria-controls"
|
|
17
28
|
dropdown_list_id = search_input_component.get_attribute(attribute)
|
|
18
29
|
if dropdown_list_id:
|
|
19
|
-
InputUtils.
|
|
30
|
+
InputUtils._setValueByComponent(search_input_component, value)
|
|
20
31
|
xpath = f".//ul[@id='{dropdown_list_id}' and @role='listbox' ]/li[@role='option']/div/div/div/div/div/div/p[text()='{value}'][1]"
|
|
21
32
|
try:
|
|
22
|
-
drop_down_item = wait.until(
|
|
23
|
-
EC.element_to_be_clickable((By.XPATH, xpath))
|
|
24
|
-
)
|
|
33
|
+
drop_down_item = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
25
34
|
except TimeoutError as e:
|
|
26
35
|
raise TimeoutError(
|
|
27
36
|
f"Dropdown item with value '{value}' not found for component '{search_input_component.text}'."
|
|
@@ -39,33 +48,19 @@ class SearchInputUtils:
|
|
|
39
48
|
return input_components
|
|
40
49
|
|
|
41
50
|
@staticmethod
|
|
42
|
-
def __selectSearchInputComponentsByPartialLabelText(
|
|
43
|
-
wait: WebDriverWait, label: str, value: str
|
|
44
|
-
):
|
|
51
|
+
def __selectSearchInputComponentsByPartialLabelText(wait: WebDriverWait, label: str, value: str):
|
|
45
52
|
xpath = f".//div[./div/span[contains(normalize-space(text())='{label}']]/div/div/div/input[@role='combobox']"
|
|
46
|
-
SearchInputUtils.__findSearchInputComponentsByLabelPathAndSelectValue(
|
|
47
|
-
wait, xpath, value
|
|
48
|
-
)
|
|
53
|
+
SearchInputUtils.__findSearchInputComponentsByLabelPathAndSelectValue(wait, xpath, value)
|
|
49
54
|
|
|
50
55
|
@staticmethod
|
|
51
|
-
def __selectSearchInputComponentsByLabelText(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
xpath = (
|
|
55
|
-
f".//div[./div/span[text()='{label}']]/div/div/div/input[@role='combobox']"
|
|
56
|
-
)
|
|
57
|
-
SearchInputUtils.__findSearchInputComponentsByLabelPathAndSelectValue(
|
|
58
|
-
wait, xpath, value
|
|
59
|
-
)
|
|
56
|
+
def __selectSearchInputComponentsByLabelText(wait: WebDriverWait, label: str, value: str):
|
|
57
|
+
xpath = f".//div[./div/span[text()='{label}']]/div/div/div/input[@role='combobox']"
|
|
58
|
+
SearchInputUtils.__findSearchInputComponentsByLabelPathAndSelectValue(wait, xpath, value)
|
|
60
59
|
|
|
61
60
|
@staticmethod
|
|
62
61
|
def selectSearchDropdownByLabelText(wait: WebDriverWait, label: str, value: str):
|
|
63
62
|
SearchInputUtils.__selectSearchInputComponentsByLabelText(wait, label, value)
|
|
64
63
|
|
|
65
64
|
@staticmethod
|
|
66
|
-
def selectSearchDropdownByPartialLabelText(
|
|
67
|
-
wait
|
|
68
|
-
):
|
|
69
|
-
SearchInputUtils.__selectSearchInputComponentsByPartialLabelText(
|
|
70
|
-
wait, label, value
|
|
71
|
-
)
|
|
65
|
+
def selectSearchDropdownByPartialLabelText(wait: WebDriverWait, label: str, value: str):
|
|
66
|
+
SearchInputUtils.__selectSearchInputComponentsByPartialLabelText(wait, label, value)
|
|
@@ -4,36 +4,35 @@ from selenium.webdriver.support import expected_conditions as EC
|
|
|
4
4
|
|
|
5
5
|
class TabUtils:
|
|
6
6
|
"""
|
|
7
|
-
Utility class for
|
|
7
|
+
Utility class for handling tab components in a web application using Selenium.
|
|
8
|
+
Example usage:
|
|
9
|
+
from selenium import webdriver
|
|
10
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
11
|
+
from robo_appian.components.TabUtils import TabUtils
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
driver = webdriver.Chrome()
|
|
14
|
+
wait = WebDriverWait(driver, 10)
|
|
10
15
|
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
TabUtils.selectInactiveTab(wait, "Settings")
|
|
16
|
+
# Find a selected tab by its label
|
|
17
|
+
selected_tab = TabUtils.findSelectedTabByLabelText(wait, "Tab Label")
|
|
14
18
|
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
# Select an inactive tab by its label
|
|
20
|
+
TabUtils.selectInactiveTabByLabelText(wait, "Inactive Tab Label")
|
|
21
|
+
|
|
22
|
+
driver.quit()
|
|
18
23
|
"""
|
|
19
24
|
|
|
20
25
|
@staticmethod
|
|
21
|
-
def
|
|
26
|
+
def findSelectedTabByLabelText(wait, label):
|
|
22
27
|
"""
|
|
23
28
|
Finds the currently selected tab by its label.
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Returns:
|
|
30
|
-
The Selenium WebElement for the selected tab.
|
|
31
|
-
|
|
30
|
+
:param wait: Selenium WebDriverWait instance.
|
|
31
|
+
:param label: The label of the tab to find.
|
|
32
|
+
:return: WebElement representing the selected tab.
|
|
32
33
|
Example:
|
|
33
|
-
TabUtils.
|
|
34
|
+
component = TabUtils.findSelectedTabByLabelText(wait, "Tab Label")
|
|
34
35
|
"""
|
|
35
|
-
# This method locates a tab that is currently selected and contains the specified label.
|
|
36
|
-
|
|
37
36
|
xpath = f".//div[./div[./div/div/div/div/div/p/strong[normalize-space(text())='{label}']]/span[text()='Selected Tab.']]/div[@role='link']"
|
|
38
37
|
try:
|
|
39
38
|
component = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
@@ -44,21 +43,17 @@ class TabUtils:
|
|
|
44
43
|
return component
|
|
45
44
|
|
|
46
45
|
@staticmethod
|
|
47
|
-
def
|
|
46
|
+
def selectInactiveTabByLabelText(wait, label):
|
|
48
47
|
"""
|
|
49
|
-
Selects
|
|
50
|
-
|
|
51
|
-
Parameters:
|
|
52
|
-
wait: Selenium WebDriverWait instance.
|
|
53
|
-
label: The visible text label of the tab to select.
|
|
48
|
+
Selects an inactive tab by its label.
|
|
54
49
|
|
|
50
|
+
:param wait: Selenium WebDriverWait instance.
|
|
51
|
+
:param label: The label of the tab to select.
|
|
52
|
+
:return: None
|
|
55
53
|
Example:
|
|
56
|
-
TabUtils.
|
|
54
|
+
TabUtils.selectInactiveTabByLabelText(wait, "Tab Label")
|
|
57
55
|
"""
|
|
58
|
-
# This method locates a tab that contains a label with the specified text.
|
|
59
|
-
|
|
60
56
|
xpath = f".//div[@role='link']/div/div/div/div/div[./p/span[text()='{label}']]"
|
|
61
|
-
# xpath=f".//div[./div[./div/div/div/div/div/p/strong[normalize-space(text())='{label}']]/span[text()='Selected Tab.']]/div[@role='link']"
|
|
62
57
|
try:
|
|
63
58
|
component = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
64
59
|
except TimeoutError as e:
|
|
@@ -5,98 +5,77 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|
|
5
5
|
|
|
6
6
|
class TableUtils:
|
|
7
7
|
"""
|
|
8
|
-
Utility class for
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# Find a table using a column name
|
|
8
|
+
Utility class for handling table operations in Selenium WebDriver.
|
|
9
|
+
Example usage:
|
|
10
|
+
from selenium import webdriver
|
|
11
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
13
12
|
from robo_appian.components.TableUtils import TableUtils
|
|
13
|
+
|
|
14
|
+
driver = webdriver.Chrome()
|
|
15
|
+
wait = WebDriverWait(driver, 10)
|
|
14
16
|
table = TableUtils.findTableByColumnName(wait, "Status")
|
|
17
|
+
row_count = TableUtils.rowCount(table)
|
|
18
|
+
component = TableUtils.findComponentFromTableCell(wait, 1, "Status")
|
|
19
|
+
driver.quit()
|
|
15
20
|
|
|
16
21
|
"""
|
|
17
22
|
|
|
18
23
|
@staticmethod
|
|
19
24
|
def findTableByColumnName(wait: WebDriverWait, columnName: str):
|
|
20
25
|
"""
|
|
21
|
-
Finds a table component
|
|
22
|
-
|
|
23
|
-
Parameters:
|
|
24
|
-
wait: Selenium WebDriverWait instance.
|
|
25
|
-
columnName: The name of the column to search for in the table.
|
|
26
|
-
|
|
27
|
-
Returns:
|
|
28
|
-
The Selenium WebElement for the table component.
|
|
26
|
+
Finds a table component by its column name.
|
|
29
27
|
|
|
28
|
+
:param wait: Selenium WebDriverWait instance.
|
|
29
|
+
:param columnName: The name of the column to search for.
|
|
30
|
+
:return: WebElement representing the table.
|
|
30
31
|
Example:
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
component = TableUtils.findTableByColumnName(wait, "Status")
|
|
33
33
|
"""
|
|
34
|
-
# This method locates a table that contains a header cell with the specified column name.
|
|
35
|
-
# It uses XPath to find the table element that has a header cell with the specified 'columnName'.
|
|
36
|
-
# The 'abbr' attribute is used to match the column name, which is a common practice in Appian UI tables.
|
|
37
34
|
|
|
38
|
-
# xpath = f".//table[./thead/tr/th[@abbr='{columnName}']]"
|
|
39
35
|
xpath = f'.//table[./thead/tr/th[@abbr="{columnName}"]]'
|
|
40
36
|
try:
|
|
41
37
|
component = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
42
38
|
except TimeoutError as e:
|
|
43
|
-
raise TimeoutError(
|
|
44
|
-
f"Could not find table with column name '{columnName}': {e}"
|
|
45
|
-
)
|
|
39
|
+
raise TimeoutError(f"Could not find table with column name '{columnName}': {e}")
|
|
46
40
|
except Exception as e:
|
|
47
|
-
raise RuntimeError(
|
|
48
|
-
f"Could not find table with column name '{columnName}': {e}"
|
|
49
|
-
)
|
|
41
|
+
raise RuntimeError(f"Could not find table with column name '{columnName}': {e}")
|
|
50
42
|
return component
|
|
51
43
|
|
|
52
44
|
@staticmethod
|
|
53
45
|
def rowCount(tableObject):
|
|
54
46
|
"""
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Parameters:
|
|
58
|
-
tableObject: The Selenium WebElement representing the table.
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
The number of rows in the table.
|
|
47
|
+
Counts the number of rows in a table.
|
|
62
48
|
|
|
49
|
+
:param tableObject: The Selenium WebElement representing the table.
|
|
50
|
+
:return: The number of rows in the table.
|
|
63
51
|
Example:
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
row_count = TableUtils.rowCount(table)
|
|
66
53
|
"""
|
|
67
|
-
# This method counts the number of rows in a table by finding all the table row elements
|
|
68
|
-
# that do not have the 'data-empty-grid-message' attribute.
|
|
69
54
|
|
|
70
55
|
xpath = "./tbody/tr[./td[not (@data-empty-grid-message)]]"
|
|
71
|
-
|
|
56
|
+
try:
|
|
57
|
+
rows = tableObject.find_elements(By.XPATH, xpath)
|
|
58
|
+
except Exception as e:
|
|
59
|
+
raise RuntimeError(f"Could not count rows in table: {e}")
|
|
72
60
|
return len(rows)
|
|
73
61
|
|
|
74
62
|
@staticmethod
|
|
75
|
-
def
|
|
63
|
+
def __findColumNumberByColumnName(tableObject, columnName):
|
|
76
64
|
"""
|
|
77
|
-
Finds the column number in a table
|
|
78
|
-
|
|
79
|
-
Parameters:
|
|
80
|
-
tableObject: The Selenium WebElement representing the table.
|
|
81
|
-
columnName: The name of the column to find.
|
|
82
|
-
|
|
83
|
-
Returns:
|
|
84
|
-
The index of the column (0-based).
|
|
65
|
+
Finds the column number in a table by its column name.
|
|
85
66
|
|
|
67
|
+
:param tableObject: The Selenium WebElement representing the table.
|
|
68
|
+
:param columnName: The name of the column to search for.
|
|
69
|
+
:return: The index of the column (0-based).
|
|
86
70
|
Example:
|
|
87
|
-
column_number = TableUtils.
|
|
88
|
-
|
|
71
|
+
column_number = TableUtils.__findColumNumberByColumnName(table, "Status")
|
|
89
72
|
"""
|
|
90
|
-
# This method locates the column header cell with the specified column name
|
|
91
|
-
# and extracts the column index from its class attribute.
|
|
92
73
|
|
|
93
74
|
xpath = f'./thead/tr/th[@scope="col" and @abbr="{columnName}"]'
|
|
94
75
|
component = tableObject.find_element(By.XPATH, xpath)
|
|
95
76
|
|
|
96
77
|
if component is None:
|
|
97
|
-
raise ValueError(
|
|
98
|
-
f"Could not find a column with abbr '{columnName}' in the table header."
|
|
99
|
-
)
|
|
78
|
+
raise ValueError(f"Could not find a column with abbr '{columnName}' in the table header.")
|
|
100
79
|
|
|
101
80
|
class_string = component.get_attribute("class")
|
|
102
81
|
partial_string = "headCell_"
|
|
@@ -108,9 +87,7 @@ class TableUtils:
|
|
|
108
87
|
selected_word = word
|
|
109
88
|
|
|
110
89
|
if selected_word is None:
|
|
111
|
-
raise ValueError(
|
|
112
|
-
f"Could not find a class containing '{partial_string}' in the column header for '{columnName}'."
|
|
113
|
-
)
|
|
90
|
+
raise ValueError(f"Could not find a class containing '{partial_string}' in the column header for '{columnName}'.")
|
|
114
91
|
|
|
115
92
|
data = selected_word.split("_")
|
|
116
93
|
return int(data[1])
|
|
@@ -118,26 +95,18 @@ class TableUtils:
|
|
|
118
95
|
@staticmethod
|
|
119
96
|
def findComponentFromTableCell(wait, rowNumber, columnName):
|
|
120
97
|
"""
|
|
121
|
-
Finds a component within a specific
|
|
122
|
-
|
|
123
|
-
Parameters:
|
|
124
|
-
wait: Selenium WebDriverWait instance.
|
|
125
|
-
rowNumber: The row number (0-based index) where the component is located.
|
|
126
|
-
columnName: The name of the column where the component is located.
|
|
127
|
-
|
|
128
|
-
Returns:
|
|
129
|
-
The Selenium WebElement for the component within the specified table cell.
|
|
98
|
+
Finds a component within a specific cell of a table by row number and column name.
|
|
130
99
|
|
|
100
|
+
:param wait: Selenium WebDriverWait instance.
|
|
101
|
+
:param rowNumber: The row number (0-based index).
|
|
102
|
+
:param columnName: The name of the column to search in.
|
|
103
|
+
:return: WebElement representing the component in the specified cell.
|
|
131
104
|
Example:
|
|
132
|
-
component = TableUtils.findComponentFromTableCell(wait,
|
|
133
|
-
|
|
105
|
+
component = TableUtils.findComponentFromTableCell(wait, 1, "Status")
|
|
134
106
|
"""
|
|
135
|
-
# This method locates a specific component within a table cell based on the provided row number
|
|
136
|
-
# and column name. It constructs an XPath that targets the table cell containing the specified column
|
|
137
|
-
# and row, and then retrieves the component within that cell.
|
|
138
107
|
|
|
139
108
|
tableObject = TableUtils.findTableByColumnName(wait, columnName)
|
|
140
|
-
columnNumber = TableUtils.
|
|
109
|
+
columnNumber = TableUtils.__findColumNumberByColumnName(tableObject, columnName)
|
|
141
110
|
# xpath=f'./tbody/tr[@data-dnd-name="row {rowNumber+1}"]/td[not (@data-empty-grid-message)][{columnNumber}]'
|
|
142
111
|
# component = tableObject.find_elements(By.XPATH, xpath)
|
|
143
112
|
rowNumber = rowNumber + 1
|
|
@@ -146,12 +115,8 @@ class TableUtils:
|
|
|
146
115
|
try:
|
|
147
116
|
component = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
|
|
148
117
|
except TimeoutError as e:
|
|
149
|
-
raise TimeoutError(
|
|
150
|
-
f"Could not find component in cell at row {rowNumber}, column '{columnName}': {e}"
|
|
151
|
-
)
|
|
118
|
+
raise TimeoutError(f"Could not find component in cell at row {rowNumber}, column '{columnName}': {e}")
|
|
152
119
|
except Exception as e:
|
|
153
|
-
raise RuntimeError(
|
|
154
|
-
f"Could not find component in cell at row {rowNumber}, column '{columnName}': {e}"
|
|
155
|
-
)
|
|
120
|
+
raise RuntimeError(f"Could not find component in cell at row {rowNumber}, column '{columnName}': {e}")
|
|
156
121
|
# childComponent=component.find_element(By.xpath("./*"))
|
|
157
122
|
return component
|