Issue with bounding box after update

Hallo,

I am still a bit new to robot framework, so starting up.

So I have recently updated my test framework:
Python: 3.9 → 3.10
Robotframework: 4.1.1 → 6.1
Robotframework-browser: 8.0.2 → 16.2.0

After this update the “Get BoundingBox” keyword does not work anymore in some cases.

This error is shown:
image

I try to explain this as good as I can. Here is the Pease of the code, so when ${elements} only has 1 entry (in list) than it works. However when there are more entries (in my case 4) than it does not work and the error is shown. I have investigate all variables, and they contain the expected data. Also when compared to the old versions I used it all checks out, and there it works as expected. Any help will be much appreciated.

${elements}=    Get Elements    ${selector}
FOR    ${element}    IN    @{elements}
    ${box}=    Get BoundingBox    ${element}
    IF    ${box}
        Append To List    ${bounded_elements}    ${element}
    END
END
1 Like

Hi Andre,

You’ve jumped quite a few versions so something might have changed behaviour slightly

There is nothing in the documentation that Get BoundingBox supports a list of elements or element selectors, however the documentation does mention

Keyword uses strict mode, see Finding elements for more details about strict mode.

Following that link tells you

If strict mode is true and locator finds multiple elements from the page, keyword will fail

And that would probably cause ${box} to be equal to None and explain the error you’re getting.

I would suggest you start with adding the line:

Log    ${element}

before the line

${box}=    Get BoundingBox    ${element}

and after that add

Log    ${box}

To check that ${element} is a single element and not a list and to see what was returned to ${box}, that way you can try to narrow down which of those changes is causing you issues.

Dave.

Hi Dave,

First of all, thanks for replying to my question.

Since the “FOR ${element} IN @{elements}” iteration will make sure that “Get BoundingBox” only has to deal with 1 element at a time, I do not think that the “strict mode” is the issue. I have tested it to be sure, but with the same result.

I have done some more tests, as suggested. If I log the ${element} before “Get BoundingBox” I get 1 element, as expected. So “Get BoundingBox” only has to deal with 1 element at the time. However it fails right away at the first element, so the variable ${box} is never set

Code:
FOR ${element} IN @{elements}
Log ${element}
${box}= Get BoundingBox ${element}
Log ${box}
IF ${box}
Append To List ${bounded_elements} ${element}
END
END

Result:

So I did also test if the iteration works, by only logging the elements. This works as expected

code:
FOR ${element} IN @{elements}
Log ${element}
END

Result:
All 4 expected elements are logged

So it it seems to be certain that the issue is with the “Get BoundingBox” keyword in combination with “FOR…IN” iteration.

Regards,

Andre

Hi Andre,

Just looking at your reply I realised what might be the problem, is the contents of @{elements} the output of something like Get Elements?

referring to the documentation for Get BoundingBox, the first argument is:

selector <str>

It’s expecting a string not an element (object), so maybe you need to approach your for loop differently?

If I’m right then you couldtry something like this

${ecount}=    Get Count    @{elements}
FOR    ${i}    IN RANGE    ${ecount}
    ${box}=    Get BoundingBox    (//you/xpath/to/elements)[${i}]
END

Dave.

Hi,

After testing, reading, learning :slightly_smiling_face:, I found the issue.

We are using “get boundingbox” to check it the item is really shown on the webpage, because there can be more but 1 is shown. In the old versions the iteration continued when there was no bounding box and eventually found 1 with a result, but now the test stops and fails when there is no boundingbox found.

So I tried to fix it with “Run Keyword And Ignore Error”, this works but makes the test way slower… So anyone any suggerstions on that? :wink:

Hi Andre,

I suspect it’s not Run Keyword And Ignore Errorthat’s causing the slowness but rather Get Boundingbox is running until it times out.

You might be able to use Set Browser Timeout to set the timeout to a lower value say 30 sec just before you call Run Keyword And Ignore Errorand Get Boundingbox but don’t forget to set the timeout back before you continue (see example in the help for how to do that)

Dave.

Hi,

It is bin a while before I was able to pick this up further, so now the update is:

Python: 3.9 → 3.12
Robotframework: 4.1.1 → 7.0
Robotframework-browser: 8.0.2 → 18.5.1

I continued with fresh inspiration. Now I see there is a difference in the result if “get elements” in version 8.0.2 it replied with something like this: ${elements} = [‘element=2ec24859-6c7c-4b9b-9e6f-21b7e2d1ac70’, ‘element=7bb4b2a7-5e2e-442b-a674-cf4602526c9a’

In version 18.5.1 it replies like this: ${elements} = [‘.MenuPaneV >> nth=0’, ‘.MenuPaneV >> nth=1’ this causes probably the issue with Get BoundingBox.

So, is there a way to get the return of “ID’ s”? as it was in the old version. Or is there any other method? I would also be happy if there is any documentation about this “change” I was not able to find it yet.

Thankyou in advance for anyone who can help a bit :smiley:

Hi Andre,

That change in the behaviour of get elements happened quite a while ago about version 16 I think. I suspect It wasn’t initiated by browser library but by playwright that browser library uses, but I don’t know for sure.

This thread might be of interest: Difference between 17.3.0 and 15.1.0 in Get Element

All I can suggest you update your tests to the way Browser Library works now and hopefully it won’t change again :crossed_fingers:

Dave.

Hi Dave,

Thanks for quick reply, the case you mentioned is indeed the same issue as I encountered. So this “issue” can be closed here, I will flag you last answer as the “solution”.

1 Like