Evaluate JavaScript

Hi

I can run the below in the console without any problems. When I run it within robot using the browserlibrary, I get the returned error:

Error: locator.evaluate: Unsupported token “{” while parsing css selector “(function(){ document.getElementById(“tree”).scrollTop = document.getElementById(“tree”).scrollHeight; })()”. Did you mean to CSS.escape it?
Call log:

  • waiting for (function(){ document.getElementById(“tree”).scrollTop = document.getElementById(“tree”).scrollHeight; })()

Evaluate JavaScript (function(){ document.getElementById("tree").scrollTop = document.getElementById("tree").scrollHeight; })()

Any ideas? Thanks in advance.

Hi @_daryl ,

that `Evaluate JavaScript´ also gave me so many headaches :sweat_smile:
If I see it correctly, you just want to run some JS code without passing any arguments.
If that’s the case, try it like that:

Evaluate JavaScript () => { document.getElementById("tree").scrollTop = document.getElementById("tree").scrollHeight; }

or

Evaluate JavaScript { document.getElementById("tree").scrollTop = document.getElementById("tree").scrollHeight; }

Please don’t ask for any explanation, it’s just my gut feeling after spending some hours on that topic…

1 Like

Hi @Many

Its been a while; I hope all is well :slight_smile:
Ive tried as that already unfortunately and I get the same error :frowning:
Thanks for suggestions though and yes, many headaches with `Evaluate JavaScript´

@_daryl Try this
Evaluate JavaScript ${None} document.getElementById("tree").scrollTop = document.getElementById("tree").scrollHeight;

2 Likes

Thanks, that works @falcon030

Unless I misunderstood the docs, the selector isn’t needed but feels as though it is.

Oh, of course!
That damn selector!
Totally forgot about that…

1 Like