4

I'm attempting to inject JavaScript directly into a page in order to set a variable for the page. I'm still rather new to the IDE and I have seen the runScript function and I think it does what I need, but it's not working at all.

What I have currently:

runScript
javascript{var selectedComponentIDs = [x,y,z];}

selectedComponentIDs is the variable in the source code of the page, that I need to change.

I really need to be able to do this with the IDE so use the Web Driver will not be a suitable answer. It must be with the IDE if it's at all possible.

Alex Kulinkovich
6272 gold badges8 silver badges18 bronze badges
asked Feb 25, 2014 at 20:14

1 Answer 1

5

First: You need to remove the javascript{} part. The runScript option just accepts plain Javascript, no need for the extra syntax.

Here is an example usage of the runScript (as seen in the Selenium IDE source tab):

<tr>
 <td>open</td>
 <td>http://www.google.com</td>
 <td></td>
</tr>
<tr>
 <td>runScript</td>
 <td>document.getElementById('gbqfq').value='test'</td>
 <td></td>
</tr>

Just ran this on my Firefox Selenium IDE and it works, please verify that this indeed works. Its should fill in "test" in the google search box. This should mean you can execute JavaScript from the IDE.

Second: I think you need to be able to access the variable you want to update/set. This can be hard if the IDE cannot acces its scope directly. Maybe you or the developers can add a Global function to the page so you can call it with "functionName();" also see https://stackoverflow.com/questions/9354191/calling-custom-functions-from-firebug-console for more idea's on calling functions from the browser console (or the runScript command, which is comparable)

You should be able to practise/test run the commands from the Firefox console before you add them to your Selenium scripts, since this can be hard to debug from the IDE.

answered Mar 11, 2014 at 18:39
1
  • Thank you, sadly while the method does work, it will not work for what I need due to a lot more processing that is done on the back end. Thanks for the answer, will be useful long term. Commented Mar 11, 2014 at 18:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.