Refer the article New Selenium IDE – Commands (Selenese), for the complete list of Selenium IDE commands and their practical demonstrations.
else is one of the commands in Selenium IDE and we need to use it with if and end commands (Refer if and end commands here).
else is the command in Selenium IDE will be executed when the if condition results in false.
The purpose of the if command is to check whether the given condition is true or false. If the condition results in true, the Selenium IDE statements inside the if block will be executed. If the condition results in false, the Selenium IDE statements inside the else block will be executed.
The else command will work as depicted below:
Let’s get started.
New Selenium IDE – Using ‘else’ command
Follow the below steps for practicing else command in Selenium IDE along with me:
1) Let’s create a test in Selenium IDE for retrieving the title of the page, adding if condition to check whether the retrieved title is equal to the expected title text, else to execute its block when the retrieved title is not equal to the expected title text and printing the result using the below Selenium IDE code:
[su_table alternate=”no”]
Command | Target | Value |
---|---|---|
open | http://omayo.blogspot.com/ | |
store title | x | |
if | ${x} === “xyz” | |
echo | Correct title is displayed on the web page | |
else | ||
echo | Wrong title is displayed on the web page | |
end |
[/su_table]
After incorporating the commands in the above table, our Selenium IDE should look like below:
2) Click on ‘Run current test’ option and observe that the test got successfully executed and the text ‘wrong title is displayed on the page’ inside the else block is printed in the Log tab as shown below:
Note: Also observe that the if block is skipped from execution.
Here concludes the practical demonstration of else command in Selenium IDE.
In the next article, I will practically demonstrate another Selenium IDE command.
Next Steps:
- > Check complete Selenium Tutorial Contents here (Click here)
Please leave your questions/comments/feedback below.
Happy Learning ?
On a mission to contribute to the Software Testing Community in all possible ways.
Refer the article New Selenium IDE – Commands (Selenese), for the complete list of Selenium IDE commands and their practical demonstrations.