ComponentUtils API Reference¶
The ComponentUtils class provides fundamental utilities for component interaction, date operations, and element validation in Robo Appian.
Import¶
Date Utilities¶
today()¶
Returns today's date formatted as MM/DD/YYYY.
Returns:
- str: Today's date in MM/DD/YYYY format
Example:
today_date = ComponentUtils.today()
print(f"Today's date: {today_date}") # Output: Today's date: 08/03/2025
yesterday()¶
Returns yesterday's date formatted as MM/DD/YYYY.
Returns:
- str: Yesterday's date in MM/DD/YYYY format
Example:
yesterday_date = ComponentUtils.yesterday()
print(f"Yesterday's date: {yesterday_date}") # Output: Yesterday's date: 08/02/2025
Component Location Methods¶
findComponentUsingXpath(wait, xpath)¶
Finds a component using the given XPath in the current WebDriver instance.
Parameters:
- wait (WebDriverWait): WebDriverWait instance to wait for elements
- xpath (str): XPath string to locate the component
Returns:
- WebElement: The located WebElement
Raises:
- NoSuchElementException: If the element is not found
Example:
component = ComponentUtils.findComponentUsingXpath(wait, "//button[@id='submit']")
component.click()
findComponentUsingXpathAndClick(wait, xpath)¶
Finds a component using the given XPath and clicks it.
Parameters:
- wait (WebDriverWait): WebDriverWait instance to wait for elements
- xpath (str): XPath string to locate the component
Returns:
- None
Example:
findChildComponent(wait, component, xpath)¶
Finds a child component using the given XPath within a parent component.
Parameters:
- wait (WebDriverWait): WebDriverWait instance to wait for elements
- component (WebElement): Parent WebElement to search within
- xpath (str): XPath string to locate the child component
Returns:
- WebElement: The located child WebElement
Example:
parent_component = driver.find_element(By.ID, "parent")
child_component = ComponentUtils.findChildComponent(wait, parent_component, ".//button[@class='child']")
findComponentsByXPath(wait, xpath)¶
Finds all components matching the given XPath and returns a list of valid components that are clickable and displayed.
Parameters:
- wait (WebDriverWait): WebDriverWait instance to wait for elements
- xpath (str): XPath string to locate components
Returns:
- List[WebElement]: List of valid WebElement components
Raises:
- Exception: If no valid components are found
Example:
components = ComponentUtils.findComponentsByXPath(wait, "//button[@class='submit']")
for component in components:
component.click()
Validation Methods¶
checkComponentExistsByXpath(wait, xpath)¶
Checks if a component with the given XPath exists in the current WebDriver instance.
Parameters:
- wait (WebDriverWait): WebDriverWait instance to wait for elements
- xpath (str): XPath string to locate the component
Returns:
- bool: True if the component exists, False otherwise
Example:
if ComponentUtils.checkComponentExistsByXpath(wait, "//div[@id='success-message']"):
print("Success message found!")
else:
print("Success message not found!")
checkComponentExistsById(driver, id)¶
Checks if a component with the given ID exists in the current WebDriver instance.
Parameters:
- driver (WebDriver): WebDriver instance to check for the component
- id (str): ID of the component to check
Returns:
- bool: True if the component exists, False otherwise
Example:
exists = ComponentUtils.checkComponentExistsById(driver, "submit-button")
print(f"Component exists: {exists}")
findCount(wait, xpath)¶
Finds the count of components matching the given XPath.
Parameters:
- wait (WebDriverWait): WebDriverWait instance to wait for elements
- xpath (str): XPath string to locate components
Returns:
- int: Count of components matching the XPath
Example:
count = ComponentUtils.findCount(wait, "//div[@class='item']")
print(f"Number of items found: {count}")
Utility Methods¶
tab(wait)¶
Simulates a tab key press in the current WebDriver instance.
Parameters:
- wait (WebDriverWait): WebDriverWait instance to wait for elements
Returns:
- None
Example:
Complete Usage Example¶
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from robo_appian.utils.ComponentUtils import ComponentUtils
def test_component_utils():
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
try:
driver.get("https://example.com")
# Get today's date for form filling
today = ComponentUtils.today()
yesterday = ComponentUtils.yesterday()
print(f"Today: {today}, Yesterday: {yesterday}")
# Check if a component exists before interacting
if ComponentUtils.checkComponentExistsByXpath(wait, "//input[@id='date-field']"):
date_field = ComponentUtils.findComponentUsingXpath(wait, "//input[@id='date-field']")
date_field.send_keys(today)
# Count how many buttons are on the page
button_count = ComponentUtils.findCount(wait, "//button")
print(f"Found {button_count} buttons on the page")
# Find and click all submit buttons
submit_buttons = ComponentUtils.findComponentsByXPath(wait, "//button[contains(@class, 'submit')]")
for button in submit_buttons:
button.click()
# Use tab to navigate
ComponentUtils.tab(wait)
# Check if operation was successful
if ComponentUtils.checkComponentExistsByXpath(wait, "//div[@class='success']"):
print("Operation completed successfully!")
finally:
driver.quit()
if __name__ == "__main__":
test_component_utils()
Related Components¶
- ButtonUtils - For button-specific operations
- InputUtils - For input field operations
- TableUtils - For table operations
ComponentUtils
¶
Classes¶
ComponentUtils
¶
Source code in robo_appian/utils/ComponentUtils.py
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 | |
Functions¶
checkComponentExistsById(driver, id)
staticmethod
¶
Checks if a component with the given ID exists in the current WebDriver instance.
:param driver: WebDriver instance to check for the component :param id: ID of the component to check :return: True if the component exists, False otherwise Example usage: exists = ComponentUtils.checkComponentExistsById(driver, "submit-button") print(f"Component exists: {exists}")
Source code in robo_appian/utils/ComponentUtils.py
checkComponentExistsByXpath(wait, xpath)
staticmethod
¶
Checks if a component with the given XPath exists in the current WebDriver instance.
Source code in robo_appian/utils/ComponentUtils.py
findChildComponent(wait, component, xpath)
staticmethod
¶
Finds a child component using the given XPath within a parent component.
:param wait: WebDriverWait instance to wait for elements :param component: Parent WebElement to search within :param xpath: XPath string to locate the child component :return: WebElement if found, raises NoSuchElementException otherwise Example usage: from selenium.webdriver.support.ui import WebDriverWait from selenium import webdriver
driver = webdriver.Chrome() wait = WebDriverWait(driver, 10) parent_component = driver.find_element(By.ID, "parent") xpath = ".//button[@class='child']" child_component = ComponentUtils.findChildComponent(wait, parent_component, xpath)
Source code in robo_appian/utils/ComponentUtils.py
findComponentUsingXpath(wait, xpath)
staticmethod
¶
Finds a component using the given XPath in the current WebDriver instance.
:param wait: WebDriverWait instance to wait for elements :param xpath: XPath string to locate the component :return: WebElement if found, raises NoSuchElementException otherwise Example usage: component = ComponentUtils.findComponentUsingXpath(wait, "//button[@id='submit']") component.click()
Source code in robo_appian/utils/ComponentUtils.py
findComponentUsingXpathAndClick(wait, xpath)
staticmethod
¶
Finds a component using the given XPath and clicks it.
:param wait: WebDriverWait instance to wait for elements :param xpath: XPath string to locate the component :return: None Example usage: from selenium.webdriver.support.ui import WebDriverWait from selenium import webdriver
driver = webdriver.Chrome() wait = WebDriverWait(driver, 10) xpath = "//button[@id='submit']" ComponentUtils.findComponentUsingXpathAndClick(wait, xpath)
Source code in robo_appian/utils/ComponentUtils.py
findComponentsByXPath(wait, xpath)
staticmethod
¶
Finds all components matching the given XPath and returns a list of valid components that are clickable and displayed.
:param wait: WebDriverWait instance to wait for elements :param xpath: XPath string to locate components :return: List of valid WebElement components Example usage: components = ComponentUtils.findComponentsByXPath(wait, "//button[@class='submit']") for component in components: component.click()
Source code in robo_appian/utils/ComponentUtils.py
findCount(wait, xpath)
staticmethod
¶
Finds the count of components matching the given XPath.
:param wait: WebDriverWait instance to wait for elements :param xpath: XPath string to locate components :return: Count of components matching the XPath Example usage: count = ComponentUtils.findCount(wait, "//div[@class='item']") print(f"Number of items found: {count}")
Source code in robo_appian/utils/ComponentUtils.py
tab(wait)
staticmethod
¶
Simulates a tab key press in the current WebDriver instance.
:param wait: WebDriverWait instance to wait for elements :return: None Example usage: ComponentUtils.tab(wait)
Source code in robo_appian/utils/ComponentUtils.py
today()
staticmethod
¶
Returns today's date formatted as MM/DD/YYYY.
yesterday()
staticmethod
¶
Returns yesterday's date formatted as MM/DD/YYYY.