Search code examples
automationrobotframeworkweb-testing

How to get substring in the given string from Robot Framework?


Given String "Showing 1 to 10 of 3,311 entries". I need to get the 3,311 separately form that string. I can use this ${Number} = Get Substring ${countString} 19 24 but here problem is index was changed.


Solution

  • You can use the Split String keyword and separate the each part of string by ${SPACE}
    Additionaly I removed , from the number just in case you need it. Slightly different way to achieve same - https://stackoverflow.com/a/57786634/5400362

    *** Variable ***
    ${string1}=        Showing 1 to 10 of 3,311 entries
    
    *** Testcases ***
    Get Number From String
    
    @{list_string}=     split string    ${string1}      ${SPACE}
    log             ${list_string}[5]
    ${num}=         evaluate       '${list_string}[5]'.replace(',','')
    

    output

    enter image description here