0

I am using expected conditions and waiting until a SVG element is located. My locator is correct when checked manually but every time the test is failing with an 'invalid locator' error message. I am really stuck. Are there any specific expected conditions to use with SVG elements or can't we use them at all? Could anyone please help?

My function:

def check_element_presence(self, locator, timeout=300):
    """
    Check if a web element is present on the web console or not.


    Args:
         locator (tuple): (GUI element needs to operate on (str), type (By))
         timeout (int): Looks for a web element repeatedly until timeout (sec) occurs
    Returns:
        bool: True if the element is found, returns False otherwise and raises NoSuchElementException

    """
    try:
        wait = WebDriverWait(self.driver, timeout=timeout)
        wait.until(ec.presence_of_element_located(locator))
        return True
    except NoSuchElementException:
        self.take_screenshot()
        logger.error("Expected element not found on UI")
        return False

This is the DOM snippet:

< svg fill="#3e8635" height="2em" width="2em" viewBox="0 0 512 512" aria- hidden="true" role="img" data-test="success-icon" style="vertical-align: -0.25em;"

my locator = ("//*[name()='svg' and @data-test='success-icon']", By.XPATH)

Thanks in advance! :)

0 Answers0