Skip to content

ComponentUtils API Reference

The ComponentUtils class provides fundamental utilities for component interaction, date operations, and element validation in Robo Appian.

Import

from robo_appian.utils.ComponentUtils import ComponentUtils

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:

ComponentUtils.findComponentUsingXpathAndClick(wait, "//button[@id='submit']")


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:

ComponentUtils.tab(wait)  # Presses Tab key

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()

ComponentUtils

Classes

ComponentUtils

Source code in robo_appian/utils/ComponentUtils.py
class ComponentUtils:
    @staticmethod
    def today():
        """
        Returns today's date formatted as MM/DD/YYYY.
        """

        from datetime import date

        today = date.today()
        yesterday_formatted = today.strftime("%m/%d/%Y")
        return yesterday_formatted

    @staticmethod
    def yesterday():
        """
        Returns yesterday's date formatted as MM/DD/YYYY.
        """

        from datetime import date, timedelta

        yesterday = date.today() - timedelta(days=1)
        yesterday_formatted = yesterday.strftime("%m/%d/%Y")
        return yesterday_formatted

    @staticmethod
    def findChildComponent(wait: WebDriverWait, component: WebElement, xpath: str):
        """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)
        """
        return component.find_element(By.XPATH, xpath)

    @staticmethod
    def findComponentUsingXpathAndClick(wait: WebDriverWait, xpath: str):
        """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)
        """
        component = ComponentUtils.findComponentUsingXpath(wait, xpath)
        component.click()

    @staticmethod
    def findComponentUsingXpath(wait: WebDriverWait, xpath: str):
        """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()
        """
        component = wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
        return component

    @staticmethod
    def checkComponentExistsByXpath(wait: WebDriverWait, xpath: str):
        """Checks if a component with the given XPath exists in the current WebDriver instance."""
        status = False
        try:
            ComponentUtils.findComponentUsingXpath(wait, xpath)
            status = True
        except NoSuchElementException:
            pass

        return status

    @staticmethod
    def checkComponentExistsById(driver: WebDriver, id: str):
        """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}")
        """
        status = False
        try:
            driver.find_element(By.ID, id)
            status = True
        except NoSuchElementException:
            pass

        return status

    @staticmethod
    def findCount(wait: WebDriverWait, xpath: str):
        """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}")
        """

        length = 0

        try:
            component = wait.until(EC.presence_of_all_elements_located((By.XPATH, xpath)))
            length = len(component)
        except NoSuchElementException:
            pass

        return length

    @staticmethod
    def tab(wait: WebDriverWait):
        """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)
        """
        driver = wait._driver
        actions = ActionChains(driver)
        actions.send_keys(Keys.TAB).perform()

    @staticmethod
    def findComponentsByXPath(wait: WebDriverWait, xpath: str):
        """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()
        """
        # Wait for the presence of elements matching the XPath
        wait.until(EC.presence_of_element_located((By.XPATH, xpath)))

        # Find all matching elements
        driver = wait._driver
        components = driver.find_elements(By.XPATH, xpath)

        # Filter for clickable and displayed components
        valid_components = []
        for component in components:
            try:
                if component.is_displayed() and component.is_enabled():
                    valid_components.append(component)
            except Exception:
                continue

        if len(valid_components) > 0:
            return valid_components

        raise Exception(f"No valid components found for XPath: {xpath}")
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
@staticmethod
def checkComponentExistsById(driver: WebDriver, id: str):
    """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}")
    """
    status = False
    try:
        driver.find_element(By.ID, id)
        status = True
    except NoSuchElementException:
        pass

    return status
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
@staticmethod
def checkComponentExistsByXpath(wait: WebDriverWait, xpath: str):
    """Checks if a component with the given XPath exists in the current WebDriver instance."""
    status = False
    try:
        ComponentUtils.findComponentUsingXpath(wait, xpath)
        status = True
    except NoSuchElementException:
        pass

    return status
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
@staticmethod
def findChildComponent(wait: WebDriverWait, component: WebElement, xpath: str):
    """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)
    """
    return component.find_element(By.XPATH, xpath)
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
@staticmethod
def findComponentUsingXpath(wait: WebDriverWait, xpath: str):
    """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()
    """
    component = wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
    return component
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
@staticmethod
def findComponentUsingXpathAndClick(wait: WebDriverWait, xpath: str):
    """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)
    """
    component = ComponentUtils.findComponentUsingXpath(wait, xpath)
    component.click()
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
@staticmethod
def findComponentsByXPath(wait: WebDriverWait, xpath: str):
    """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()
    """
    # Wait for the presence of elements matching the XPath
    wait.until(EC.presence_of_element_located((By.XPATH, xpath)))

    # Find all matching elements
    driver = wait._driver
    components = driver.find_elements(By.XPATH, xpath)

    # Filter for clickable and displayed components
    valid_components = []
    for component in components:
        try:
            if component.is_displayed() and component.is_enabled():
                valid_components.append(component)
        except Exception:
            continue

    if len(valid_components) > 0:
        return valid_components

    raise Exception(f"No valid components found for XPath: {xpath}")
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
@staticmethod
def findCount(wait: WebDriverWait, xpath: str):
    """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}")
    """

    length = 0

    try:
        component = wait.until(EC.presence_of_all_elements_located((By.XPATH, xpath)))
        length = len(component)
    except NoSuchElementException:
        pass

    return length
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
@staticmethod
def tab(wait: WebDriverWait):
    """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)
    """
    driver = wait._driver
    actions = ActionChains(driver)
    actions.send_keys(Keys.TAB).perform()
today() staticmethod

Returns today's date formatted as MM/DD/YYYY.

Source code in robo_appian/utils/ComponentUtils.py
@staticmethod
def today():
    """
    Returns today's date formatted as MM/DD/YYYY.
    """

    from datetime import date

    today = date.today()
    yesterday_formatted = today.strftime("%m/%d/%Y")
    return yesterday_formatted
yesterday() staticmethod

Returns yesterday's date formatted as MM/DD/YYYY.

Source code in robo_appian/utils/ComponentUtils.py
@staticmethod
def yesterday():
    """
    Returns yesterday's date formatted as MM/DD/YYYY.
    """

    from datetime import date, timedelta

    yesterday = date.today() - timedelta(days=1)
    yesterday_formatted = yesterday.strftime("%m/%d/%Y")
    return yesterday_formatted