Get Text results in error in case of SVG element

I am doing my first POC with Browser library so I am not sure whether I am doing everything correctly (if what I am doing is supported), so want to double check before submitting issue.

When I am using Get Text keyword with SVG element (obtained using Get Element keyword) I am getting error:

local variable 'value' referenced before assignment

Minimal Example:

*** Settings ***
Library    Browser    timeout=30

*** Test Cases ***
Demo SVG - Fails
    New Browser    firefox    headless=${False}
    New Page    https://www.highcharts.com/demo/responsive
    ${parents}    Get Elements    //*[local-name()="g" and contains(@class, "highcharts-legend-item")]
    FOR    ${element}    IN    @{parents}
        ${rect_el}    Get Element    ${element} >> xpath=./*[local-name()="rect"]
        ${fill}    Get Attribute    ${rect_el}    fill
        ${text_el}    Get Element    ${element} >> xpath=./*[local-name()="text"]
        ${text}    Get Text    ${text_el}
    END

I think you cannot declare a variable inside a loop in RF.
In RF you should use Collections library
First you “create list” then inside of a loop you will “append to list”

But I am not sure what are you trying to accomplish with that test :slight_smile: Please provide a little context so I can be more specific.

And CSS selectors enable a bit clearer selector :).
${parents} = Get Elements g.highcharts-legend-item

Variables inside loops are allowed, it’s not issue. Problem is with Get Text keyword. As workaround used Get Property keyword and got textContent.

workaround and actual error almost feels like its a bug in the lib.

Took at look at the code and yeah, it is a bug in Browserlibrary code: Get text keyword bug · Issue #957 · MarketSquare/robotframework-browser · GitHub

2 Likes

@rasjani Thank you!

1 Like

Thank you for reporting the issue. Good news is that issue should be fixed in next release: Sometimes element text can be empty by aaltat · Pull Request #989 · MarketSquare/robotframework-browser · GitHub

1 Like

Investigating issue more and found more problems to be fixed. Therefore this is not fixed in the 4.5.0. The 4.5.0 contains only updated Playwright 1.11.0. Will be part of the 4.6.0 release.