[Python] When using 'Get element attribute' it adds a value count. Is it possible to neglect...

Discussão em 'Python' iniciado por Stack, Novembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I want to get a value from a textbox that's automically generated from user input in different textboxs and dates.

    ${var} get element attribute xpath=path_to_xpath value
    log ${var}


    When checking the log the output is as following:

    GENERATEDINPUT_V001

    GENERATEDINPUT_V002

    GENERATEDINPUT_V003

    I don't need the _V001, V002, V003 part, but I don't see an option to neglect it. This is the documentation of the 'Get element Attribute' keyword:

    def get_element_attribute(
    self, locator: Union[WebElement, str], attribute: str
    ) -> str:
    """Returns the value of ``attribute`` from the element ``locator``.

    See the `Locating elements` section for details about the locator
    syntax.

    Example:
    | ${id}= | `Get Element Attribute` | css:h1 | id |

    Passing attribute name as part of the ``locator`` was removed
    in SeleniumLibrary 3.2. The explicit ``attribute`` argument
    should be used instead.
    """
    return self.find_element(locator).get_attribute(attribute)

    @keyword


    I know it's possible to strip the part, but is there an easier way like a on/off setting?

    I checked the documentation and browsed online for a solution

    If you need to strip it:

    ${Var_without_valuecount} = Get Substring ${Var} 0 -5
    log ${Var_without_valuecount}


    Now the log shows: GENERATEDINPUT

    Continue reading...

Compartilhe esta Página