rookievmc
rookievmc

Reputation: 183

Robot Framework Execute Javascript Execution Error

Any idea why I keep getting the below error, when I try to execute my robot test case?

JavascriptException: Message: SyntaxError: missing ) after argument list

When I trie to execute the below keyword

     Execute Javascript  document.getElementByXpath('//button[contains(.,'Help')]').onclick();

Upvotes: 1

Views: 1404

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193088

This error message...

JavascriptException: Message: SyntaxError: missing ) after argument list

...implies that there was a syntax error within the expression.

You need to replace the outer single quote i.e. '...' with double quote i.e. "..." as follows:

Execute Javascript  document.getElementByXpath("//button[contains(.,'Help')]").onclick();

As an alternative you can also use document.evaluate() as follow`:

Execute JavaScript document.evaluate('//button[contains(.,"Help")]',document.body,null,9,null).singleNodeValue.click();

Outro

Clicking Element with JavaScript on Robot Framework

Upvotes: 1

Todor Minakov
Todor Minakov

Reputation: 20057

You've used single quotes for both the argument of getElementByXpath() and the xpath's contains() function; this closed the js function's call unexpectedly. Change one to use double quotes:

document.getElementByXpath("//button[contains(.,'Help')]").onclick()

Upvotes: 2

Related Questions