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

Value of variable '@{attributes}' is not list or list-like. #2513

Closed
4WvgqJu opened this issue Jan 4, 2023 · 3 comments · Fixed by #2524
Closed

Value of variable '@{attributes}' is not list or list-like. #2513

4WvgqJu opened this issue Jan 4, 2023 · 3 comments · Fixed by #2524
Assignees
Milestone

Comments

@4WvgqJu
Copy link

4WvgqJu commented Jan 4, 2023

Describe the bug
My observation concerns function Get Attribute Names of library Browser. The error occurs when the script on the website examines the attributes of the elements with context HREF.

To Reproduce
Run the code snippet with an appropriate website:

Library     Browser
Library     Collections
Library     CryptoLibrary

*** Variables ***
${attribute}=           empty
${attributes}=          empty
${element}=             empty
${elements}=            empty
${elementHref}=         xpath=//a
${page2}=               @your-page/your-script.php
${protocol}=            http://
${value}=               empty
${url2}=                ${protocol}${this_is_whoever}:${this_is_secret}${page2}

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}
            ${value}=       Get Property    ${element}      href
            Log             ${value} 
            ${attributes}=  Get Attribute Names     ${element}       
            FOR     ${attribute}    IN  @{attributes}
                Log             ${attribute}
            END            
    END
    Take Screenshot                
    Close Browser           CURRENT

Expected behavior
The Get Attribute Names function does not change the data type from list to string if the list contains only one attribute name. Or in other words, the return value of the function is always the list data type even if the list contains only one element.

Screenshots
image

Desktop (please complete the following information):

  • OS Microsoft Windows 10 Pro
  • Version 10.0.19044 Build 19044
  • Browser Google Chrome
  • Version Version 108.0.5359.125 (Offizieller Build) (64-Bit)

Additional context
I am now changing my paradigm to get around the behavior with the standard Run Keyword If function and an additional keyword for a FOR ... END loop and case distinction. But that's work for me again! Once to identify the error and look for a solution. I would find it better if the data type is always list, if only one element.

@aaltat
Copy link
Member

aaltat 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.

@Snooz82
Copy link
Member

Snooz82 commented Jan 5, 2023

Posted by @4WvgqJu in a new issue.
I closed that new issue and reopened this one for clarification.

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 Snooz82 reopened this Jan 5, 2023
@Snooz82
Copy link
Member

Snooz82 commented Jan 5, 2023

@aaltat We actually have the current behaviour that Keywords that use list_verify_assertion do return a single value if there is only one element in that list and None if the list is empty.

it is done by map_list in assertionengine project. so technically it would be a BWIC in AssersionEngine and Browser

@Snooz82 Snooz82 self-assigned this Jan 6, 2023
@Snooz82 Snooz82 added this to the v14.4.0 milestone Jan 6, 2023
Snooz82 added a commit that referenced this issue Jan 6, 2023
Signed-off-by: René <snooz@posteo.de>
Snooz82 added a commit that referenced this issue Jan 7, 2023
Signed-off-by: René <snooz@posteo.de>
Snooz82 added a commit that referenced this issue Jan 8, 2023
…2522 #2523 #2530

- [x] fixed __init__.pyi file
- [x] removed deprecated Keywords `Get Element State` & `Execute Javascript`
- [x] fixed #2522 that clean_up of screenshots etc happens only once per robot run.
- [x] fixed #2513 list getters always shall return lists
- [x] removed support for direct values of `Fill Secret`, `Type Secret` and `httpCredentials` argument from `New Context` #2523 
- [x] fixed New Context with recordVideo without size does not default to viewport. #2530
- [x] removed `videoSize` and `videoPath` arguments from `New Context` and `New Persistent Context`
- [x] fixed #2214 recordVideo with New Persistent Context
- [x] fixed #2215 New Persistent Context did not return Video Path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants