Manali February 2016

org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: missing ) after argument list

I am working on selenium webdriver and I need to enter text without using sendkeys method, because the search popup text field is hidden. So I wrote below code:

1st way:

((JavascriptExecutor)driver).executeScript("document.getElementByXpath('//input[@class='form-control input-small input-inline']').value='TextValue'");

2nd Way:

JavascriptExecutor jse = (JavascriptExecutor) driver;
//jse.executeScript("document.getElementByXpath('//input[@class='form-control input-small input-inline']').value ='abcd';");

3rd way:

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].type ='search';",chemObject.getSearchPopup());

but I am getting syntax error as I mentioned in the title.

Answers


Andrew Regan February 2016

Your first one is producing the JavaScript error, and the reason is mixed-up single quotes, which you wouldn't have seen from the Java code, not until the JS was executed.

The simplest fix is to replace:

((JavascriptExecutor)driver).executeScript("document.getElementByXpath('//input[@class='form-control input-small input-inline']').value='TextValue'");

with:

((JavascriptExecutor)driver).executeScript("document.getElementByXpath(\"//input[@class='form-control input-small input-inline']\").value='TextValue'");

However, it still won't work for you (nor your second attempt), because getElementByXpath isn't a JavaScript DOM method.

This is all covered in a very similar thread here.

Post Status

Asked in February 2016
Viewed 3,937 times
Voted 7
Answered 1 times

Search




Leave an answer