Issue 5192 in selenium: JavascriptExecutor dies when including a 'var'

3 views
Skip to first unread message

sele...@googlecode.com

unread,
Feb 19, 2013, 4:47:12 PM2/19/13
to selenium-develope...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium Status-Untriaged

New issue 5192 by karl.por...@gmail.com: JavascriptExecutor dies when
including a 'var'
http://code.google.com/p/selenium/issues/detail?id=5192

What steps will reproduce the problem?
1. Create a test case using Webdriver.
2. Paste the following code in the test.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return var x = 'something'; alert(x);");

3. Run your test.

What is the expected output? What do you see instead?
I would expect to see an alert box with the message 'something' inside it.
What I see is my test failing with the below error message:

org.openqa.selenium.WebDriverException: SyntaxError: syntax error
Command duration or timeout: 32 milliseconds
Build info: version: '2.29.0', revision: '58258c3', time: '2013-01-17
22:46:35'
System info: os.name: 'Linux', os.arch: 'amd64',
os.version: '2.6.32-279.19.1.el6.x86_64', java.version: '1.7.0_09-icedtea'
Session ID: abe17c62-011d-4403-8e73-bec81f56c8f9
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, databaseEnabled=true,
cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true,
handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true,
nativeEvents=false, webStorageEnabled=true, rotatable=false,
locationContextEnabled=true, applicationCacheEnabled=true,
takesScreenshot=true, version=17.0.2}]
Command duration or timeout: 558 milliseconds
Build info: version: '2.29.0', revision: '58258c3', time: '2013-01-17
22:46:43'
System info: os.name: 'Linux', os.arch: 'x86',
os.version: '2.6.32-279.19.1.el6.x86_64', java.version: '1.6.0'
Session ID: 7c2153f8-d732-4117-b4c5-cc4b65ee2512
Capabilities [{handlesAlerts=true, rotatable=false, databaseEnabled=true,
locationContextEnabled=true, acceptSslCerts=true,
applicationCacheEnabled=true, nativeEvents=false, cssSelectorsEnabled=true,
takesScreenshot=true, platform=LINUX, browserName=firefox,
javascriptEnabled=true, version=17.0.2, webStorageEnabled=true,
webdriver.remote.sessionid=7c2153f8-d732-4117-b4c5-cc4b65ee2512,
browserConnectionEnabled=true}]
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:533)
at
org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:441)
at
com.ibm.multitool.active.selenium.SendInstructionsTest.testSendInstructionsRetainExistingCase(SendInstructionsTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)
at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)
at
org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:110)
at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)
at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
at java.util.concurrent.FutureTask.run(FutureTask.java:149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
at java.lang.Thread.run(Thread.java:738)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has
been taken
Build info: version: '2.29.0', revision: '58258c3', time: '2013-01-17
22:46:43'
System info: os.name: 'Linux', os.arch: 'x86',
os.version: '2.6.32-279.19.1.el6.x86_64', java.version: '1.6.0'
Driver info: driver.version: RemoteWebDriver
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:125)
... 27 more
Caused by: org.openqa.selenium.WebDriverException: SyntaxError: syntax error
Command duration or timeout: 32 milliseconds
Build info: version: '2.29.0', revision: '58258c3', time: '2013-01-17
22:46:35'
System info: os.name: 'Linux', os.arch: 'amd64',
os.version: '2.6.32-279.19.1.el6.x86_64', java.version: '1.7.0_09-icedtea'
Session ID: abe17c62-011d-4403-8e73-bec81f56c8f9
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, databaseEnabled=true,
cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true,
handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true,
nativeEvents=false, webStorageEnabled=true, rotatable=false,
locationContextEnabled=true, applicationCacheEnabled=true,
takesScreenshot=true, version=17.0.2}]
Build info: version: '2.29.0', revision: '58258c3', time: '2013-01-17
22:46:43'
System info: os.name: 'Linux', os.arch: 'x86',
os.version: '2.6.32-279.19.1.el6.x86_64', java.version: '1.6.0'
Driver info: driver.version: EventFiringWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:533)
at
org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:441)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101)
at $Proxy1.executeScript(Unknown Source)
at
org.openqa.selenium.support.events.EventFiringWebDriver.executeScript(EventFiringWebDriver.java:209)
at
org.openqa.selenium.remote.server.handler.ExecuteScript.call(ExecuteScript.java:55)
at
org.openqa.selenium.remote.server.handler.ExecuteScript.call(ExecuteScript.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at
org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:167)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

================================

If you replace the below line:
js.executeScript("return var x = 'something'; alert(x);");

with the following:
js.executeScript("return alert('something');");

Everything works just fine. My test always fails whenever I include
a 'var' in the JavaScript.

Selenium version: 2.29.0
OS:
Linux Client for e-business (RHEL) 6.3 (Gold Master)
Open Client RHEL 64 3.30 (Gold Master)
Red Hat Enterprise Linux Workstation release 6.3 (Santiago)

Browser: Firefox
Browser version: 17.0.2 ESR


Please provide any additional information below. A sample reduced test
case, or a public URL that demonstrates the problem will intrigue our merry
band of Open Source developers far more than nothing at all: they'll be far
more likely to look at your problem if you make it easy for them!

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

sele...@googlecode.com

unread,
Feb 19, 2013, 5:32:09 PM2/19/13
to selenium-develope...@googlegroups.com
Updates:
Status: WorkingAsIntended
Labels: -Status-Untriaged

Comment #1 on issue 5192 by james.h....@gmail.com: JavascriptExecutor dies
If I try to enter the following in the Firebug console, I receive a syntax
error:

function zz() { return var x; alert('hello'); }; zz();

This is functionally equivalent to what WebDriver's executeScript() method
is doing, creating a function and immediately executing the function
created. If your JavaScript is syntactically invalid, the
JavascriptExecutor will not be able to work at all.

Executing the following, however, works fine for me:

((JavascriptExecutor)driver).executeScript("var x = 2; alert('hello');
return x;");

It's perfectly acceptable to use the "var" keyword in your JavaScript, and
it's perfectly valid to return a value from your JavaScript, but "return
var" is invalid JavaScript syntax.

sele...@googlecode.com

unread,
Feb 20, 2013, 8:39:25 AM2/20/13
to selenium-develope...@googlegroups.com

Comment #2 on issue 5192 by karl.por...@gmail.com: JavascriptExecutor dies
Thanks for setting me straight, I misunderstood how this statement works.

Regards
Reply all
Reply to author
Forward
0 new messages