Javascript executor issues in Java Beanshell?

647 views
Skip to first unread message

David

unread,
Jul 19, 2012, 7:54:32 PM7/19/12
to webdriver
I was wondering if anyone encountered Javascript executor issues in
Java Beanshell?

The only Beanshell issue I've found before was this with sendKeys:

http://groups.google.com/group/webdriver/browse_thread/thread/be568157b38ee47b/f83818c0d28afc49?lnk=gst&q=beanshell#f83818c0d28afc49

wonder if my JS executor issue is related or something else.

Did I miss an import or some class/package reference? Or improper
casting? I've had no issues using javascript executor in plain Java,
but I like to do exploratory development in Beanshell than to code,
compile, run, edit, repeat in Java IDE.

Here's what I get trying to do some exploratory test development
trying to automate some stuff:

1.3.0 - by Pat Niemeyer (p...@pat.net)
bsh % import org.openqa.selenium.*;
bsh % import org.openqa.selenium.firefox.*;
bsh % System.setProperty("webdriver.firefox.bin", "/Applications/
Firefox12/Firefox.app/Contents/MacOS/firefox-bin");
bsh % WebDriver d = new FirefoxDriver();
bsh % d.get("http://www.somesite.com");
bsh % JavascriptExecutor js = (JavascriptExecutor) d;
bsh % js.executeScript("document.getElementById('photoFile').value = '/
Users/ettqa/Dropbox/Photos/Stitch.jpg';");
// Error: EvalError: Error in method invocation: Method
executeScript( java.lang.String ) not found in
class'org.openqa.selenium.firefox.FirefoxDriver' : at Line: 1 : in
file: <unknown file> : js .executeScript
( "document.getElementById('photoFile').value = '/Users/ettqa/Dropbox/
Photos/Stitch.jpg';" )

bsh % js.executeScript("return window.name;");
// Error: EvalError: Error in method invocation: Method
executeScript( java.lang.String ) not found in
class'org.openqa.selenium.firefox.FirefoxDriver' : at Line: 1 : in
file: <unknown file> : js .executeScript ( "return window.name;" )

bsh % js.executeScript("window.localStorage.clear();");
// Error: EvalError: Error in method invocation: Method
executeScript( java.lang.String ) not found in
class'org.openqa.selenium.firefox.FirefoxDriver' : at Line: 1 : in
file: <unknown file> : js .executeScript
( "window.localStorage.clear();" )

bsh % ((JavascriptExecutor)
d).executeScript("window.localStorage.clear();");
// Error: EvalError: reflection error: bsh.ReflectError: Method
executeScript( java.lang.String ) not found in
class'org.openqa.selenium.firefox.FirefoxDriver' : at Line: 1 : in
file: <unknown file> : .executeScript
( "window.localStorage.clear();" )

bsh %

David

unread,
Aug 14, 2012, 9:29:16 PM8/14/12
to webdriver
Sigh, no response? It really sucks to not be able to use javascript
executor in Beanshell right now.

Wish I could get some help/insight into this issue.

On Jul 19, 4:54 pm, David <manga...@gmail.com> wrote:
> I was wondering if anyone encountered Javascript executor issues in
> Java Beanshell?
>
> The only Beanshell issue I've found before was this with sendKeys:
>
> http://groups.google.com/group/webdriver/browse_thread/thread/be56815...

Alexandr Savchuk

unread,
Sep 3, 2012, 12:24:59 PM9/3/12
to webd...@googlegroups.com
Try to use js.executeScript("javascript code", new Object[] {})

Signature of this method is "public Object executeScript(String script, Object... args)".

David

unread,
Sep 5, 2012, 9:10:04 PM9/5/12
to webdriver
Thanks Alexandr, that seems to work.

I'm having trouble working out a working example using a WebElement as
an argument, but it looks like extending your suggestion, you can
supply arguments as follows, as I got using static values for
arguments working ok.

js.executeScript("javascript code that uses arguments[0],
arguments[1], and on", new Object[] {someWebElement, "some value for
arg 1"});
Reply all
Reply to author
Forward
0 new messages