Since Java 6 there is the package javax.script (look it up in the API documentation) that you can use to run scripts in different scripting languages. An interpreter for JavaScript is included.
Can you explain in more detail what exactly you want to use this for? Is this JavaScript on a web page, which the browser normally runs for you?
linda russel wrote:Actually i just want to run a simple javascript which has a alert message by calling it in my java program.
Frankly, that sounds like a pretty bad idea. Can you give some more context as to what exactly you're trying to do? Besides the obvious, that is. Are you writing a web application using JSPs? What is this Java program doing that it needs to make a call out to Javascript? Javascript is a client-side technology. Java programs run in a JVM. There's a huge chasm between those two that you're trying to bridge and people don't normally try to do that (think Evel Knievel jumping the Grand Canyon). Now as others have hinted, there are ways to legitimately work with Javascript from Java but I'm interested to see if your intent is compatibly legitimate.
Actually i am doing Selenium automation using webdriver API's , the problem is that i have few HTML5 components and HTML5 canvas for which i do not have any Webdriver API's so i am trying to call a external javascript
linda russel wrote:Actually i am doing Selenium automation using webdriver API's , the problem is that i have few HTML5 components and HTML5 canvas for which i do not have any Webdriver API's so i am trying to call a external javascript
Ah, so you're actually doing some Evel Knievel stuff, huh? I don't do much work with WebDriver/Selenium at that level but there is a JavascriptExecutor interface documented here: http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html. That might be a place to start searching for a solution.
BTW, Java in General may not be the best forum to have this thread. Testing maybe? I'll defer that decision to the folks in charge of this bar though.
Post by:autobot
Can't .... do .... plaid .... So I did this tiny ad instead:
a bit of art, as a gift, the permaculture playing cards