robotframeworkrobotframework-browser

Can I capture the value of 'value' attribute and save it as a variable?


I would like to capture the value of an input element and save it as a string variable in Robot Framework. How would I do this?

The element structure is as follows:

<input name="name" class="input" type="text" value="Default Text">

I would like to capture the "Default Text" value and save it in a string using Robot Framework and Browser Library.


Solution

  • Let's assume the xpath is as below:

    //input[@name = 'name']
    

    Then to get element attribute

    ${GET_ATTR_ELE}   Get Attribute    //input[@name = 'name']   value
    

    where ${GET_ATTR_ELE} is the variable.
    Then set the variable to use it later

    Set Test Variable    ${GET_ATTR_ELE}
    

    Hope this helps!