Refer the article New Selenium IDE – Commands (Selenese), for the complete list of Selenium IDE commands and their practical demonstrations.
else if is one of the commands in Selenium IDE and we need to use it with if, else and end commands (Refer if, else and end command here).
else if is the command in Selenium IDE will be executed when the if condition results in false and we have another condition to be validated before going to the else block.
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 if block will be skipped and the next else if condition will be checked for true or false. If the else if condition is true, the statements inside the else if block will be executed. And if the else if condition is false, the else if block will be skipped and the next else if condition or else block will be executed.
The else if command will work as depicted below:
Let’s get started.
New Selenium IDE – Using ‘else if’ command
Follow the below steps for practicing else if 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 one text, else if condition to check whether the retrieved title is equal to the expected title two text, else to execute its block when the retrieved title is not equal to the expected title one and title two texts 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 one is displayed on the web page | |
else if | ${x} === “omayo (QAFox.com)” | |
echo | Correct title two 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 ‘Correct title two is displayed on the page’ inside the else if block is printed in the Log tab as shown below:
Note: Also observe that the if block and else block are skipped from execution.
Here concludes the practical demonstration of else if 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.