Can't get an attribute from an element

Hello,

I’m using Robot Framework 3.2.1 and trying to get an attribute from an element on the Facebook page.
The id of the element is changing every time the code is executed because something is shared on Facebook.
This is the piece of code:

${hrefLastSharedActivity}= Execute JavaScript return document.getElementsByClassName(“kgnml90y om3e55n1 g4tp4svg”)[0].getElementsByTagName(“a”)[0].getAttribute(“href”)

The locator “kgnml90y om3e55n1 g4tp4svg” is a class that is not changing and this used to work until the class was changed on Facebook. I replaced the locator class and is not working anymore.

Executing this in the Chrome browser console is returning the attribute “href” that I need so I guess the code is correct.

I get the following error in Robot Framework: “JavascriptException: Message: javascript error: Cannot read properties of undefined (reading ‘getAttribute’)”

Any ideas about what I’m doing wrong?

Thanks.