If you want to run longer javascript code with the selenium java api, you’ll need to use the selenium.getEval(String jsCode); method. Also you have to consider, that only the last line of the javascript code is returned.
For Example, if you have a TextModifier Object in your page which has the Method inverseString(StringToInverse) , a HTML-Element with known id, which name is “dlroW” and you’ll run the following command:
String result = selenium.getEval("var h = ' olleH';
var name = selenium.browserbot.getCurrentWindow().document. getElementById('"+id+"').name;
var hw = selenium.browserbot.getCurrentWindow(). TextModifier.inverseString(name+h);
hw ");
The result will be Hello World
Cheers,
strayparade
Tags: getEval, java, javascript, selenium