Variables in Selenium IDE

You can store and later reuse values in Selenium IDE.

Storing values?

<tr>
<td>storeEval</td>
<td>window.document.domain</td>
<td>variableName</td>
</tr>

All store commands start with store. A few examples:

  • storeEval: Stores the value of a JavaScript snippet.
  • storeAttribute: Can store the value of an html attribute.
    Example
    If you have: <href id=”example-id”>Hello world</href>
    Then: StoreAttribute | link=Hello World@id | idVariable
    Will give: example-id
  • there are many more store commands actually! Intelli-senseĀ  in the IDE will certainly help you!

Getting/using values?

You can reuse your stored values with ${variableName}. If you want to just display it in the log use:

<tr>
<td>echo</td>
<td>${variableName}</td>
<td></td>
</tr>

Getting variables from url parameters in Selenium IDE

Are you using paramaterized url’s and would you like to get it’s value to later use in Selenium IDE?

If you have an url like this: http://localhost:8318/#type=page&id=331 and you would like to get the value from id. It’s actually quite simple!

Just use JavaScript! Using this one-line regex you’ll get the result:
new RegExp(‘&id=([0-9]+)’).exec(‘http://localhost:8318/#type=page&id=331’)[1]

So this should get you started:

<tr>
<td>storeLocation</td>
<td>url</td>
<td></td>
</tr>

<tr>
<td>storeEval</td>
<td>new RegExp(‘&amp;id=([0-9]+)’).exec(‘${url}’)[1]</td>
<td>varId</td>
</tr>

<tr>
<td>echo</td>
<td>${varId}</td>
<td></td>
</tr>

 

 

Selenium simulate enter key

Are you using Selenium IDE? This is a Firefox plugin to help you create interface test for your web project. If you use Javascript or Ajax, and want to see the result of an interaction, you sometimes need to simulate pressing the ENTER key.

If your code acts upon releasing the enter key, this might help you:

<tr>
<td>keyUp</td>
<td>css=div.yourclass</td>
<td>\13</td>
</tr>

Does your web project do something upon pressing in the enter key? Then try this:

<tr>
<td>keyDown</td>
<td>css=div.yourclass</td>
<td>\13</td>
</tr>

Selenium and TinyMCE

Selenium is a tool to automatically test your web interface. You have to write a set of commands, which Selenium will execute and report if something did fail. Selenium IDE is the plugin for Firefox that enables you to create these commands.

If you are using TinyMCE as your WYSIWYG editor for textboxes, you might have a problem. Since TinyMCE runs in an iframe, it is not simple to add content to that.

The easiest way I found to add a text to your TinyMCE is to add it via Javascript. Use runScript as the method and use this javascript command: tinyMCE.activeEditor.setContent(“A banana is an edible fruit produced by several kinds of large herbaceous flowering plants of the genus Musa”);

Or paste this in the contents of your Selenium file:

<tr>
<td>runScript</td>
<td>tinyMCE.activeEditor.setContent(&quot;A banana is an edible fruit produced by several kinds of large herbaceous flowering plants of the genus Musa.&quot;);</td>
<td></td>
</tr>