Get result from ExecuteScript

75 views
Skip to first unread message

Dominic Lennon

unread,
Mar 27, 2013, 9:13:24 AM3/27/13
to seleniu...@googlegroups.com
Hi,

I am attempting to execute some JavaScript on my device using the ExecuteScript method. I try store the result in a variable, however I always get null back as the result. Is this a known issue?

Dom

Arran

unread,
Mar 27, 2013, 10:44:19 AM3/27/13
to seleniu...@googlegroups.com
We will need to see your exact code but one major thing to note is that a lot of people forget to literally return the variable, for instance they run this (C#):

driver.ExecuteScript("someVariable;");

Which, in real JavaScript and using the various Console's in each browser would actually work and print out the variable and it's contents, but in WebDriver, you'll have to explicitly return it, tell it I want the value back!

driver.ExecuteScript("return someVariable;");

Dominic Lennon

unread,
Mar 28, 2013, 5:44:23 AM3/28/13
to seleniu...@googlegroups.com
Awesome :D Its working now!!
Reply all
Reply to author
Forward
0 new messages