Re: Possible typecasting problem and anyone use Selenium/WebDriver with Beanshell?
David Luu <[email protected]> Fri, 17 Aug 2012 11:36:52 -0700
| Newsgroups | gmane.comp.java.beanshell.user |
|---|---|
| Message-ID | <CA+V6+ZAbkHQoY0kkyvPiKZTVHqDUYXQypTpN93s+Ju6c09Sg0A@mail.gmail.com> |
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 <inline_four-/[email protected]>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 <[email protected]>
> *To:* beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> *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
> Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> 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/