Sri
Sri

Reputation: 309

Selenium WebDriver executeScript not working

I am using the script to set the value of the hidden form field variable formContent to the value 'Hello'. Selenium Webdriver doesn't set the value of the hidden form field as it is not visible.

Here is my code:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return jQuery('input:hidden[id$=\"formContent\"]').val('Hello');");

I am getting the script is unresponsive. Could you please tell me what I am doing wrong here. The formContent is defined in my xhtml as follows:

<input type="hidden" id="formContent" name="formContent" value="" />

If use the following lines of code, then it is not setting the value of the hidden form field "formContent":

 JavascriptExecutor js = (JavascriptExecutor) driver;
 js.executeScript("jQuery('input:hidden[id$=\"formContent\"]').val('Hello');");

Thanks!

Upvotes: 1

Views: 9096

Answers (1)

Keith Bentrup
Keith Bentrup

Reputation: 11995

I believe it's a bug with the Firefox webdriver. I experienced something similar when trying to return jQuery objects and described the behavior here: http://code.google.com/p/selenium/issues/detail?id=3756

Try returning something other than a jQuery obj, and it should become responsive again. For example, you could return a boolean value of your executed code by just prefixing it with !! like this:

js.executeScript("return !!jQuery('input:hidden[id$=\"formContent\"]').val('Hello');");

Upvotes: 1

Related Questions