Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using if / else in selenium ide

I have a checkbox that I'm trying to click in Selenium IDE - but only if it's not already active.

I'm using Selenium IDE to create my tests, and htmlsuite to run them - anyone know how I can use an "if" in those?

like image 461
Hippyjim Avatar asked Jun 30 '12 15:06

Hippyjim


People also ask

What is the difference between if and end in Selenium IDE?

if is one of the commands in Selenium IDE and we need to end it with end command. if and end are two commands in Selenium IDE which can be used together. The purpose of the if command is to check whether the given condition is true or false.

What is the ifelse command in Selenium IDE?

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.

What is the purpose of the if command in selenium?

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 and end commands will be executed. If the condition results in false, the Selenium IDE statements inside the if and end commands won’t be executed (i.e. skipped from execution).

What is if – else statement in selenium?

If – else Statement: Let us now look into example with selenium using If Else. Earlier we have validated Page title using if block, in the same way, we have used 'driver.getTitle ()' and check if it matches with expected title. If it is true, statements in if block will be executed. If it is NOT, statements in else block will be executed


1 Answers

You'll have to download the 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.


The only alternative I know about is implementing the whole logic in javascript - including the test steps. It's possible, it's a little bit harder to get right, but if you'll end up stuck with IDE without plugins, it might be your only save:

var value = this.browserbot.findElement("id=someInput").value;
if (value == "Slanec is the best!") {
    this.browserbot.findElement("id=someButton").click();
}
like image 113
Petr Janeček Avatar answered Oct 19 '22 08:10

Petr Janeček