Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I organize "IF ELSE" in Selenium IDE

How can I organize "IF ELSE" in Selenium IDE WITHOUT use extensions?

like image 636
user1211063 Avatar asked Dec 12 '25 15:12

user1211063


2 Answers

Just to conclude it for future readers:

  1. 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.

  2. 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().

like image 101
Petr Janeček Avatar answered Dec 15 '25 23:12

Petr Janeček


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>
like image 33
Senthil Nathan Avatar answered Dec 16 '25 00:12

Senthil Nathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!