Reputation: 127
How can I organize "IF ELSE" in Selenium IDE WITHOUT use extensions?
Upvotes: 3
Views: 20015
Reputation: 747
Use Gotoif condition.
Here is an example for Gotoif condition:
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=gbqfq</td>
<td>test</td>
</tr>
<tr>
<td>echo</td>
<td>${test}</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>test</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['test']=false</td>
<td>labltest</td>
</tr>
<tr>
<td>type</td>
<td>id=gbqfq</td>
<td>test</td>
</tr>
<tr>
<td>label</td>
<td>labltest</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Thanks,
Upvotes: 1
Reputation: 38424
Just to conclude it for future readers:
The "right" and most complete way is to download a Flow Control
plugin for Selenium IDE from the official page (aaaall the way down).
The most useful link I found is this one, because it has a complete example in it: http://selenium.10932.n7.nabble.com/if-else-statement-td4370.html
Anyway, there's also a documentation and author's blogpost explaining something more.
Without any Selenium IDE plugins (what a silly demand - Selenium IDE itself is a plugin!), there's nothing you can do besides writing the whole command in JavaScript. For this, the following functions may come in handy: document.getElementById()
, document.getElementsByTagName()
, document.getElementsByClassName()
, document.querySelectorAll()
and document.evaluate()
.
Upvotes: 4
Reputation: 21
To use If..Else in selenium IDE, first add the plugin "SelBlock"/ link: https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-sel-blocks/versions/. After that only you can able to use If..Else in your test case. Example:
<head>
<body>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=signin</td>
<td>test</td>
</tr>
<tr>
<td>echo</td>
<td>${test}</td>
<td></td>
</tr>
<tr>
<td>if</td>
<td>${test}==true</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=signin</td>
<td></td>
</tr>
<tr>
<td>else</td>
<td></td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Logout')])[2]</td>
<td></td>
</tr>
<tr>
<td>endIf</td>
<td></td>
<td></td>
</tr>
</body>
Upvotes: 1