Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You are correct the return type is always list of strings, even there is only one item in the list. I think it's better that keywords have only one return type, in this case a list. Because then one doesn't need write extra handling if user have a scenario where keyword can return zero or more elements. #2514

Closed
4WvgqJu opened this issue Jan 4, 2023 · 2 comments

Comments

@4WvgqJu
Copy link

4WvgqJu commented Jan 4, 2023

    You are correct  the return type is always list of strings, even there is only one item in the list. I think it's better that keywords have only one return type, in this case a list. Because then one doesn't need write extra handling if  user have a scenario where keyword can return zero or more elements.

Originally posted by @aaltat in #2513 (comment)

@4WvgqJu
Copy link
Author

4WvgqJu commented Jan 4, 2023

Hard for me to understand what you write. Or are there no more issues? Maybe it is more understandable this way?
To my great surprise, the functions Get Count, Get Length from the library BuiltIn are not useful for counting the elements of the list. Because, the functions count either the number of characters of the element for one element in the container and the functions count the number of elements for more than one element in the container. Return value for ${attributes} = href is 4, return value for ${attributes} = ['href', 'onclick'] is 2. In other words, in the first case the function counts the characters of one element, in the other case the function counts the number of elements of the list.

It's a workaround using kind of reflection on types:

robotframework-browser issues 2513
    [Documentation]     
    ...     https://https://github.com/MarketSquare/robotframework-browser/issues/2513                
       
    [Arguments]         ${attributes}   ${attribute}
    FOR     ${attribute}    IN  @{attributes}
            Log             ${attribute}
    END 

Test Insert
    [Tags]    AI    INSERT
    
    New Browser
    Suppress Logging
    Log                     ${this_is_whoever}
    Log                     ${this_is_secret}
    New Page                ${url2} 
    Unsuppress Logging               
    Take Screenshot
    ${elements} =           Get Elements        ${elementHref} 
    FOR     ${element}      IN  @{elements}
            Log             ${element}
            ${attributes}=  Get Attribute Names     ${element}
            Log             ${attributes}
            ${type}=        Evaluate        type($attributes)                
            Run Keyword If  "${type}" == "<class${space}'list'>"        robotframework-browser issues 2513      ${attributes}   ${attribute}
            ${list}=        Run Keyword If  "${type}" == "<class${space}'str'>"         Create List     ${attributes}
            Run Keyword If  "${type}" == "<class${space}'str'>"         robotframework-browser issues 2513      ${list}   ${attribute}                
    END
    Take Screenshot                
    Close Browser           CURRENT

@Snooz82
Copy link
Member

Snooz82 commented Jan 5, 2023

Closed. Please continue on the same issue and do not open new ones.

@Snooz82 Snooz82 closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants