Selenium IDE “gotoif” “gotoLabel” and “label” commands with example

As described in my previous post(“while” and “endWhile” commands with example), selenium IDE software testing tool not supporting any conditioning and looping commands and to get support of “gotoif” “gotoLabel” and “label” commands, you have to attach user extension with selenium IDE software automation testing tool. This is Advanced Selenium IDE feature. Click here to download user extension and attach it with selenium IDE and restart selenium IDE software testing tool’s window. Now you can use “gotoif” “gotoLabel” and “label” commands with selenium IDE software automation.

“gotoif” Command in selenium IDE
As name suggest, “gotoif” command will jump on defined label if condition match. And if not found conditional match then it will execute immediate next command.
Using “gotoLabel” command in Selenium IDE
“gotoLabel” will simply jump on targeted label. It not requires any conditional match to jump on label.
Use of “label” command with “gotoif” and “gotoLabel” command
“label” command used for catching jump which is fired from “gotoif” or “gotoLabel” commands.

Let we learn all three commands with example as bellow.

New Test
Command Target Value
setSpeed 1000
open https://www.google.com/
storeLocation CurrentURL
echo ${CurrentURL}
store http://www.bing.com/ TempURL
echo ${TempURL}
gotoIf storedVars[‘CurrentURL’]!==storedVars[‘TempURL’] NOTSAMEURL
label TRYAGAIN
pause 5000
store https://www.google.com/ TempURL
gotoIf storedVars[‘CurrentURL’]!==storedVars[‘TempURL’] NOTSAMEURL
gotoLabel SAMEURL
label NOTSAMEURL
echo YOUR BOTH URLs ARE NOT SAME
pause 5000
gotoLabel TRYAGAIN
label SAMEURL
echo YOUR BOTH URLs ARE SAME NOW

Run above example in your selenium IDE software testing tool and see command execution sequence very carefully. Let me describe execution process step by step.
  • “storeLocation” command will store current opened URL “https://www.google.com/” in variable “CurrentURL”. 
  • “store” command will store “http://www.bing.com/” in variable “TempURL”
  • Now “gotoIf” command will check and compare value of variable “CurrentURL” and variable “TempURL” and jump on defined label “NOTSAMEURL” if not found same value in both the variables. In our example, “CurrentURL” contains “https://www.google.com/” and “TempURL” contains “http://www.bing.com/” so that condition does not match and execution pointer will jump on label “NOTSAMEURL” and will execute next 2 commands “echo” to print “YOUR BOTH URLs ARE NOT SAME” in log and pause command.
  • Next command “gotoLabel” will move pointer at label = “TRYAGAIN”.
  • Now “store” command will store “https://www.google.com/” in variable “TempURL”
  • Once again, next command “gotoIf” will check and compare value of variable “CurrentURL” and variable “TempURL” and now value of both the URLs are same so it will not jump on defined label but will execute next command “gotoLabel” to jump on label = “SAMEURL”.
  • Last command will print “YOUR BOTH URLs ARE SAME NOW” and your test will be completed.
Try above example with different scenarios. Let me know by posting comment bellow this post if any face any issue.

7 thoughts on “Selenium IDE “gotoif” “gotoLabel” and “label” commands with example

  1. I am getting an error as mentioned below :
    [error] Unexpected Exception: Error: Specified label 'TRY AGAIN' is not found.. fileName -> chrome://selenium-ide/content/tools.js -> file:///C:/Users/srinivasnl/Desktop/Selenium/user-extension.js?1388059782579, lineNumber -> 77, columnNumber -> 8

  2. The error you guys are getting could be because there is no space in the label TRYAGAIN. If you look at the error result "TRY AGAIN" has a space. Check you have the label correctly written with no space.

  3. Is there a way to introduce a variable in a label name? For example, if you store a unique identifier as a variable, is it possible to incorporate that variable into a label name.
    for example (and I'm not concerned about format accuracy in most of this)
    store | 123456 | X
    gotoif | X < 99999999 | ${X}blah
    store | new number X+1 | X
    label | ${X blah} |

    would be extremely handy. I've played with it some to no avail. Is it possible?

  4. Hello There,

    I regularly follow this blog and get all the helps from here.

    I am trying to 'Echo' Custom info message whenever any command from the script has failed.

    Like from within steps 1 to 20, if the step no. 14 failed then, I wanted to show message/echo 'Step 14 Verify Customer Name failed'.

    is there any way I can do such? I am trying all this things in Selenium IDE, have tried lot of stuff to do such but couldn't work this out.

    If you can help here it would be great.

    Thanks,
    Jay

  5. Hello There,

    I regularly follow this blog and get all the helps from here.

    I am trying to 'Echo' Custom info message whenever any command from the script has failed.

    Like from within steps 1 to 20, if the step no. 14 failed then, I wanted to show message/echo 'Step 14 Verify Customer Name failed'.

    is there any way I can do such? I am trying all this things in Selenium IDE, have tried lot of stuff to do such but couldn't work this out.

    If you can help here it would be great.

    Thanks,
    Jay

Leave a Reply

Your email address will not be published. Required fields are marked *