Running javascript with selenium

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: , , ,

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Log Out / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Log Out / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Log Out / Ändern )

Verbinde mit %s


Follow

Get every new post delivered to your Inbox.