Quantcast

Possible typecasting problem and anyone use Selenium/WebDriver with Beanshell?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Possible typecasting problem and anyone use Selenium/WebDriver with Beanshell?

daluu
Hello,

I don't know the internals of Beanshell nor WebDriver to be able to
determine the source problem, but hopefully others can help me shed some
light on this. I also know Beanshell is no longer being developed but any
help appreciated. I'll also gonna try with the new Beanshell2 fork and see
what I can get off there.

Using standard boilerplate example Java code to execute javascript with
WebDriver (FF or IE driver, doesnt' matter), using the example online, e.g.

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("some js here");

this runs fine under Java. Now try same code snippet under Beanshell. Get
such an exception (exact message varies by actual browser driver used):

EvalError: Error in method invocation: Method executeScript(
java.lang.String ) not found in
class'org.openqa.selenium.firefox.FirefoxDriver'.

Since code works in Java, this must be a Beanshell specific issue. But the
error message is rather vague. And since I'm not a Selenium dev nor do I
work closely with the core Java class bindings, I have no idea what the
error may be about.

My best guess is that it can't find the proper class reference to
executeScript method. Somehow referencing needs to work differently in
Beanshell? Or typecasting doesn't work? According to the docs,
JavascriptExecutor is an interface that is implemented in the different
browser WebDrivers.

FYI, I start up Beanshell with reference to Selenium JAR already as follows:

java -cp selenium-server-standalone-2.24.1.jar;bsh-2.0b4.jar bsh.Interpreter

Standard WebDriver and WebElement commands work fine like get(),
findElement(), click(). I just can't execute javascript.

Regards,
David
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Possible typecasting problem and anyone use Selenium/WebDriver with Beanshell?

daluu
Just a follow up, I also tried doing same thing using the latest Beanshell 2 JAR, still same result. So doesn't matter for Beanshell version.

And FYI, issue I'm talking about is for Selenium project:

http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_How_do_I_execute_Javascript_directly?

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Possible typecasting problem and anyone use Selenium/WebDriver with Beanshell?

Alexey Zinger
The reason this isn't working is because the actual parameter signature for JavascriptExecutor.executeScript, as per API, is (String, Object...).  So how many parameters does executeScript take?  From Java 5+ language standpoint is that it's a String followed by a variable number of Objects.  However, when you compile this down to bytecode, the parameter signature actually looks like this: (String, Object[]) and that's what Beanshell and anything driven by reflection sees.  To make your code work, you will need to revert to Java 4-compatible mode (without reliance on variable parameter invocation, which is a compiler-only feature) like this:

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("some js here", new Object[0]);

Good luck.
 
Alexey




________________________________
 From: daluu <[hidden email]>
To: [hidden email]
Sent: Thursday, August 16, 2012 2:35 PM
Subject: Re: [Beanshell-users] Possible typecasting problem and anyone use Selenium/WebDriver with Beanshell?
 
Just a follow up, I also tried doing same thing using the latest Beanshell 2
JAR, still same result. So doesn't matter for Beanshell version.

And FYI, issue I'm talking about is for Selenium project:

http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_How_do_I_execute_Javascript_directly?

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html





--
View this message in context: http://beanshell.2283338.n4.nabble.com/Possible-typecasting-problem-and-anyone-use-Selenium-WebDriver-with-Beanshell-tp4650445p4650447.html
Sent from the BeanShell - User mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Possible typecasting problem and anyone use Selenium/WebDriver with Beanshell?

daluu
Thanks for the response Alex. That's pointing me in the right direction.
Looks like it could be tricky to get working though. I tried your suggested
code, and it didn't quite work. No exception now, but it appears to be
caling the wrong signature / version of the method. Calling with object[0]
returns

[org.openqa.selenium.ie.InternetExplorerElement@776c9cf9 -> unknown locator]

The other signatures, like the one mistakenly being called, generally are
for passing a WebElement object for manipulation by javascript. Trying to
call those versions fail with exception.

System.out.println(js.executeScript("return arguments[0].value;",d.findEle
ment(By.id("searchText"))));
// Error: EvalError: Error in method invocation: Method executeScript(
java.lang
.String, org.openqa.selenium.ie.InternetExplorerElement ) not found in
class'org
.openqa.selenium.ie.InternetExplorerDriver' : at Line: 3 : in file:
<unknown fil
e> : js .executeScript ( "return arguments[0].value;" , d .findElement ( By
.id
( "searchText" ) ) )

bsh % System.out.println(js.executeScript("return
arguments[0].value;",d.findEle
ment(By.id("searchText")),new Object[0]));
// Error: EvalError: Error in method invocation: Method executeScript(
java.lang
.String, org.openqa.selenium.ie.InternetExplorerElement,
[Ljava.lang.Object; ) n
ot found in class'org.openqa.selenium.ie.InternetExplorerDriver' : at Line:
4 :
in file: <unknown file> : js .executeScript ( "return arguments[0].value;"
, d .
findElement ( By .id ( "searchText" ) ) , new Object [ 0 ] )

On Thu, Aug 16, 2012 at 5:29 PM, Alexey Zinger <[hidden email]>wrote:

> The reason this isn't working is because the actual parameter signature
> for JavascriptExecutor.executeScript, as per API<http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html>,
> is (String, Object...).  So how many parameters does executeScript take?
> From Java 5+ language standpoint is that it's a String followed by a
> variable number of Objects.  However, when you compile this down to
> bytecode, the parameter signature actually looks like this: (String,
> Object[]) and that's what Beanshell and anything driven by reflection
> sees.  To make your code work, you will need to revert to Java 4-compatible
> mode (without reliance on variable parameter invocation, which is a
> compiler-only feature) like this:
>
> import org.openqa.selenium.*;
> import org.openqa.selenium.firefox.*;
> WebDriver driver = new FirefoxDriver();
> JavascriptExecutor js = (JavascriptExecutor) driver;
> js.executeScript("some js here", new Object[0]);
>
> Good luck.
>
> Alexey
>
>
>   ------------------------------
> *From:* daluu <[hidden email]>
> *To:* [hidden email]
> *Sent:* Thursday, August 16, 2012 2:35 PM
> *Subject:* Re: [Beanshell-users] Possible typecasting problem and anyone
> use Selenium/WebDriver with Beanshell?
>
> Just a follow up, I also tried doing same thing using the latest Beanshell
> 2
> JAR, still same result. So doesn't matter for Beanshell version.
>
> And FYI, issue I'm talking about is for Selenium project:
>
>
> http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_How_do_I_execute_Javascript_directly
> ?
>
>
> http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html
>
>
>
>
>
> --
> View this message in context:
> http://beanshell.2283338.n4.nabble.com/Possible-typecasting-problem-and-anyone-use-Selenium-WebDriver-with-Beanshell-tp4650445p4650447.html
> Sent from the BeanShell - User mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Loading...