Selenium IDE Flow Control - Goto and While Loops
tldr; https://github.com/73rhodes/sideflow
This extension provides goto, gotoIf and while loop functionality in Selenium IDE. Selenium IDE is a plugin for Firefox that automates the testing of web-based applications. There is an excellent flow-control extension at wiki.openqa.org/display/SEL/flowControl for the Selenium RC and TestRunner components, but it does not work with Selenium IDE (the Firefox plugin) directly. This makes it difficult to develop controlled test cases within Selenium IDE, and there are times when the frame-based TestRunner cannot be used (such as when the website under test employs a frame-buster script).
I've ported the existing control-flow extension to work in the Selenium IDE Firefox add-on. The image below shows a sample test case using goto, gotoIf and a while loop, all running successfully in Selenium IDE.
The file can be downloaded from Github and should be saved as "sideflow.js" to your hard drive. Then the Options settings in Selenium IDE should set the Selenium Core extensions to include the path of this file, similar to the image below.
I've published the extension on github. Go ahead and download it from there.
github.com/73rhodes/sideflow
Update 26 February, 2008:
This mod of the FlowControl extension works only with the Selenium IDE Firefox add-on. If you want to use the TestRunner component or Selenium RC, please use the original FlowControl extension.
Update 19 February 2011
I've moved the extension over to github.
Update 7 July 2011
I've updated the example to use the newer syntax required in the latest versions of Selenium IDE.
Please note that if you are using Selenium RC, you should use the original flow-control plugin here: wiki.openqa.org/display/SEL/flowControl
Unfortunately I haven't had the time or the need to make this compatible with both Selenium RC and Selenium IDE. Please feel free to fork the code on github and make a pull request if you would like to help out.
Update 24 July 2012
I added a "push" command to the plugin, with a simple example on the Github page. This allows you to easily create a collection of items and implement "for each"-style functionality to iterate over it. Here's the original announcement.
This extension provides goto, gotoIf and while loop functionality in Selenium IDE. Selenium IDE is a plugin for Firefox that automates the testing of web-based applications. There is an excellent flow-control extension at wiki.openqa.org/display/SEL/flowControl for the Selenium RC and TestRunner components, but it does not work with Selenium IDE (the Firefox plugin) directly. This makes it difficult to develop controlled test cases within Selenium IDE, and there are times when the frame-based TestRunner cannot be used (such as when the website under test employs a frame-buster script).
I've ported the existing control-flow extension to work in the Selenium IDE Firefox add-on. The image below shows a sample test case using goto, gotoIf and a while loop, all running successfully in Selenium IDE.
The file can be downloaded from Github and should be saved as "sideflow.js" to your hard drive. Then the Options settings in Selenium IDE should set the Selenium Core extensions to include the path of this file, similar to the image below.

github.com/73rhodes/sideflow
Update 26 February, 2008:
This mod of the FlowControl extension works only with the Selenium IDE Firefox add-on. If you want to use the TestRunner component or Selenium RC, please use the original FlowControl extension.
Update 19 February 2011
I've moved the extension over to github.
Update 7 July 2011
I've updated the example to use the newer syntax required in the latest versions of Selenium IDE.
Please note that if you are using Selenium RC, you should use the original flow-control plugin here: wiki.openqa.org/display/SEL/flowControl
Unfortunately I haven't had the time or the need to make this compatible with both Selenium RC and Selenium IDE. Please feel free to fork the code on github and make a pull request if you would like to help out.
Update 24 July 2012
I added a "push" command to the plugin, with a simple example on the Github page. This allows you to easily create a collection of items and implement "for each"-style functionality to iterate over it. Here's the original announcement.
Comments
E.g. if you are keep trying to open the same URL1 until the response changes from URL2a to URL2b?
openAndWait | http://arstechnica.com/index.ars
storeTitle | pageTitle
storeTitle | newPageTitle
while | storedVars['pageTitle']==storedVars['newPageTitle']
pause | 1000
openAndWait | http://arstechnica.com/index.ars
storeTitle | newPageTitle
endWhile
getEval | alert("The title has changed");
"missing = in XML attribute"
in the IDE
this is with selenium 8.7
:(
Please see http://www.webmasterworld.com/forum89/13847.htm
The flow control extension doesn't throw this error message. This one is generated by the JavaScript engine and is reporting an error in the page under test.
The flow control extension throws only the following error messages:
- non-matching while/endWhile found
- invalid row)nim specified
- specified label xyz is not found
- corresponding 'endWhile' is not found
- Corresponding 'While' is not found
Cheers...
D
The bugged row is #27
switch( command_rows[i].command.toLowerCase() ) {
Error message: command_rows[i].command has no properties
count(//table//td) = 10
or
xpath=count(//table//td) = 10
I've noted that the script doesn't handle comments as a feature request.
Anonymous #2
Your eval expression doesn't appear to be valid javascript. Note that the expression is passed directly to the eval() function and must be valid javascript / DOM code. This is not the same syntax that's used for Selenium locators.
The easiest solution is to set up your variables before a while or goto using the Selenium getEval command. The parameter to getEval is the Javascript needed to do your xpath lookup. For example:
getEval |
var currentWin = this.browserbot.getCurrentWindow(); storedVars['myLinks'] = new Array(); myLinks = document.evaluate("//a[starts-with(@href, '/mylink')]", currentWin.document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null); storedVars['myLinkCount'] = myLinks.length;
This can be followed by a conditional while or goto, ie:
gotoIf | ${myLinkCount} > 10 | myTarget
Hope that helps.
Also, please not that for support questions you should use the forums at http://www.openQA.org
Add at line 27
if (command_rows[i].type == 'command') {
switch....
...
}
Failed to load user-extensions.js!
files=C:\Documents and Settings\Administrator\Desktop\goto_sel_ide.js
error=SyntaxError: illegal character
This is with version 0.8.7. I've tried saving the file several ways, but always get the same error
Thanks!
There's something hokey about the way google docs saves a file. Just highlight the entire text of the file and copy-n-paste it into a new text file and save it as goto.js or whatever.
D
I use Selenium Core with goto_sel_ide.js file. I added it to core\scripts and I have run my script with Tomcat. The 'while' loop in test script doesn't execute. And I change its name to user-extension.js. the error javascript is occurred. please help me
I'm trying to use this FlowControl extension for one of my tests and I'm running into problems.
Basically if my test is dependent on importing data. So, the first time I import the data I just hit next and proceed. But if for any reason I want to run the test again the first page is a replace page. Replace the existing data (yes/no). I want to set up my test to work either way so I don't have to code it to expect to say yes and replace like it is now.
Example.
First time it imports the data I want to execute this:
selenium.Click("ctl00_bottomButtons_lbNext");
Second time it imports the data I want to execute this:
selenium.Click("ctl00_contentHolder_lnkYes");
selenium.Click("ctl00_bottomButtons_lbNext");
I don't know how to get it to check and see if the yes control is there and if it is hit it else hit the next control. Make sense?
Use any of the Selenium selectors to test for the presence of your reset element; assign the boolean result to a stored variable. Place a goto target in front of the "click next" line. Place an if statement in front of the "click yes" line, and use the boolean as the condition. See my Selenium Test Tips post for more information. What you're trying to do is fairly simple, I'm sure you'll get it going if you perservere... :-)
|while|assertTextNotPresent|error
|click|//a[2]/img
|endwhile|
or something to that effect.
any suggestions?
Re: Selenium Flow Control
How can I create an Array and Iterate through it Selenium IDE or Core?
Thanks in advance
If you use Selenium IDE, use my version of the goto extension, if you use Selenium core, use the original goto extension.
In Selenium IDE, to create and iterate over an array, you could do this:
getEval | delete storedVars['myarray']
storeEval | new Array('a','b','c') | myarray
store | 0 | x
while | storedVars['x'] < 3
getEval | alert(storedVars['myarray'][storedVars['x']])
getEval | tmp = storedVars['x'];tmp++;storedVars['x']=tmp
endWhile
Notice that I access the internal "storedVars" directly, rather than using the ${x} syntax, for reasons cited in my post "Selenium IDE Test Tips". Also note that you might want to grab an Array like document.images rather than the simple "abc" array I created in this example.
First, thanks for the quick respond. Second, your solution worked for me..THANK U SO MUCH, I AM MOST GRATEFUL !!!
Just wonder, if you could tell what's wrong here, this loop works as expected in the selenium IDE, but when I try to run it in the selenium core. the first element is not pick up until the second loop. Also the If statement that pick up the desire html, appears to be picking up the wrong html (html A or htmlB or htmlC) . This is the skeleton step to test multilanguage website
Grateful for your insight..
storeEval | 0 | LoopCounter
storeEval | new Array('en','de','da','cs','fi','fr','it','ja','ko','nl','no','pl','pt','ru','sv','tr') | myarray
while | storedVars['LoopCounter'] < 10
storeEval | storedVars['myarray'][storedVars['LoopCounter']] | Lang
echo | ${LoopCounter
echo | ${Lang}
gotoIf | (storedVars['Lang'] || storedVars['LoopCounter'] )== " " | SkipLoop
store | | html
storeEval | if ( storedVars['Lang'] == "en" ) {html ='../tests/htmlA.html'} else if ( storedVars['Lang'] == "de ") {html ='../tests/htmlB.html'} else if ( storedVars['Lang'] == "da ") {html ='../tests/htmlC.html'} | html
echo | ${html} |
label | SkipLoop
store | javascript{storedVars.LoopCounter++}
endWhile
I haven't tried running your script but the first thing that popped into my head was this sentence from my post on Selenium IDE test tips:
"Within a single Selenium command, if you modify storedVars['x'], the value of ${x} won't get updated until the next command."
I notice you're using a mix of the ${x} and "storedVars" ways of accessing variables -- try sticking with storedVars. Also, I'm not sure how Core uses storedVars; my version of the extension is for S-IDE, so if you need help with the Core version, please check out the OpenQA website forums.
I would love to have flow control in the Selenium IDE but with 1.0b2 version, I get the following error after I load the goto_sel_ide.js extension:
"error loading Selenium IDE extensions: ReferenceError: Selenium is not defined"
Any ideas?
e.g.
'storedVars{"companyRegisteredLegalNameVar"} = ""'
[error] Unexpected Exception: message -> missing ; before statement, fileName -> chrome://selenium-ide/content/tools.js -> file:///C:/selenium-extension/goto_sel_ide.js, lineNumber -> 82, stack -> (.....
, name -> SyntaxError
e.g.
'${entityType}' == 'selectedType1'
Thanks for a useful article.
I have had some success with your example, however the gotoIf does not find the second target, it reports [error] Unexpected Exception: message -> Specified label 'target2' is not found.
If the label is before the goto it works. Any advice please?
thanks
Mike (Poole, UK)
I'd have to put your item in the "could not reproduce" category, since the example in the screen capture worked for me. You might want to check for typos, capitalized letters, or spaces in your label that you might not have noticed before. I really hope its just a typo and not really a bug, because furkelling around in the guts of Selenium isn't how I want to spend Christmas :-)
cheers
java -jar D:\Selenium\selenium-server.jar -multiwindow -userExtensions "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\userExtentions\user-extensions.js" -htmlsuite *chrome http://www.google.com/ "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Selenium IDE scripts\SuiteDataDriven.html" "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Result\Result.html"
But when i try to run in *iehta with the following command
java -jar D:\Selenium\selenium-server.jar -multiwindow -userExtensions "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\userExtentions\user-extensions.js" -htmlsuite *iehta http://www.google.com/ "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Selenium IDE scripts\SuiteDataDriven.html" "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Result\Result.html"
the following happens:
1) I get a dialog box with title "Internet explorer script error" and Message "error 'XML is undefined' do you want to continue running script on this page?" and buttons yes & no. I click the yes Button
2) It execute the open command (this happens to be the first command in my test) and then fails at the 'loadTestData' command. The result file contains the following error Unknown command: 'loadTestData'
Following is the content of the user-extentions.js file
//the content of the js is not accepted by the blog editor.
Am I doing anything wrong. It seems to work perfectly in *chrome.
I have added the *.js file to my hard drive and reflected in Selenium Options. When I try to run 'gotoif' command, i get the message:
[error] Unknown command: 'gotoif'
I'm running this on mac.
Any advise please?
Regards,
Abe
This does work on a Mac, but your text-editing program might not save the code as plain ascii text. I opened up a terminal and used vi, but if you're not comfy in Unix-land, what I suggest is to take the CD of "extras" that came with your Mac and install the Developer Tools. Then under /Developer/Applications you can find Dashcode, a pretty decent text editor for coding. Btw I just tested out with Firefox 3, latest Selenium IDE, and Mac OS X 10, no problems.
The other thing to check is make sure you add the extensions under the Selenium Core section (see screenshot).
hope this helps,
Darren
After I get to one of those pages I want to assert of verify element on one of those pages. Can I use gotoIF to do that? The page I'm redirected to will be random.
Can you give me an example of selenium html code/syntax that will accomplish this task. Thanks
I am new to Selenium IDE. I have to create a script for detecting cursor focus on any control when a page is visited. For that i have taken ID's of all controls into a variable using storeAllFields Command. I too have got length of that variable and using while loop, i have been able to move till the length of that variable.
Question is :- I am unable to get each value separately as we get in C or JAVA. How can i do that using Selenium IDE?
I'm not sure if I understand your question. I think what you want to do is jump to another section of your test if a certain element is on the page. For that, use "storeElementPresent" and use the result as the condition to "gotoIf".
Eg.
storeElementPresent|myElement|foundIt
gotoIf|foundIt|myTarget
Hope this helps,
Darren
You have to use Javascript syntax to access stored variables. I recommend using the storedVars['varibleName'] style of accessing stored variables. In your case you'll iterate as:
storedVars['myFields'][currentIndex]
That should give you access to each element in your array of IDs. Also see my post on Selenium IDE test tips for more info on variables.
Hope this helps.
Darren
I have one of three pages that I will be randomly be redirected to as soon as I hit a URL for what I call a control page. THis page allows random redirection to any one of three pages.
When I get to one of those pages then I want to make many assertions on that page. I tried something like the following:
I want to do something like the following, but am not quite sure how to pull it off:
StoreLocation Store the URL's of all three possible pages that I could be redirected to as variables.
If redirected to page A assert elements on that page.
elseif redirected to page B assert elements on page B
elseif redirected to page C assert elements on page C
Then do it all over again a few times.
Thanks
I'm a newbie to Selenium. Its been a couple of days since i made my hands wet in Selenium.
As you have mentioned in your other blog, Selenium does not have any kind of tech documentation so I'm finding it very very difficult to understand this tool.
Since I'm damn new I'm unable to say how great your tool is. But the comments from others makes me to give you 5 out of 5.
Great job...!!!!
You'll have to get the document.location to check the landing url against your stored URLs. Other than that, it sounds like your test is fairly straightforward. I you have questions related to Selenium syntax, check out the QA forums. They're a lot more active in answering questions than I am. :-)
Swami... good, hope it helps you out.
D.
Thanks,
Abhishek
Line 98 reads:
var while_row = whileLabels.ends[ last_row ] - 1;
but I'm fairly sure the '- 1' is wrong, otherwise the flow is passed back to one line *before* the start of the while loop.
Otherwise, if you have a while loop starting on the first line (which is line 0 in in the whileLabels object created by initialiseLabels) then it tries to pass control back to line '-1' which fails, obviously.
At any rate, changing the line so that it reads just:
var while_row = whileLabels.ends[ last_row ];
gives the expected behaviour for me.
I just started using Selenium and ran into your blog when I was looking for online help. Thank you for the information you have shared. It's a blessing for beginners like me.
The following question may be retarded but I am gonna ask you anyway...
I am trying to capture the (current) page title and compare it with a title I had captured earlier...
storeTitle||currentTitle
gotoIf|storedVars['currentTitle']==storedVars['classicTitle']|label1
WILL THIS WORK???
Also, How do I use the 'echo' command to make it print the value/text stored in the "currentTitle"???
Thank you for your response. The Javascript alert suggestion helped debug the issue I was facing.
Also, can you point me to any good online Selenium websites/ discussion forums??? [apart from your blog :)]
Thanks,
Suraj
My issue is no matter the condition is met or not, Selenium keeps going to the step with the label "clickrenew".
Any help with this will be appreciated.
Here are the commands I have:
gotoIf |'${AutoRenew}' == true|clickrenew
label |clickrenew
click |CheckBox_RenewText
First want to say thank you for your post and all comments. They are very helpful.
Could you please tell me where i'm wrong? I was trying to use one of your example from comments above to solve next problem:
I have an array with 3 link names
and i need to click them one by one
open| http://localhost/
storeEval| new Array('Worldwide','Asia','Europe')| myarray
store| 0| x
while| storedVars['x']<3| |
getEval| alert(storedVars['myarray'][storedVars['x']])|
store| storedVars['myarray'][storedVars['x']]| t
click| link=storedVars['t']|
getEval| tmp = storedVars['x'];tmp++;storedVars['x']=tmp|
endWhile|
Regards,
Oleg
Ukraine
First of all, I would try to populate the array by looking up the items on the page (ie. by using XPATH) instead of hard-coding them.
Secondly, if you see an [error] link="Worldwide" no found, you have a problem with your locator. Google 'Selenium locator'.
Here's a suggestion: use the automatic recording feature on Selenium IDE to perform the actions you want to automate. Save the test and study it to see what kind of actions and locators you should be using in your hand-crafted testcase.
Keep working on it, you'll get it.
First whant to say thanks for quick reply.
I've resolved the problem in next way:
I was using:
click|link=storedVars['myarray'][storedVars['x']]
And it wasn't working.
Then I tried to use following:
click|javascript{'link='+storedVars['myarray'][storedVars['x']]}
And it works!
Apparently the problem was that Selenium didn't understand that storedVars['myarray'][storedVars['x']] is a variable and processed it as a text line.
Thanks a lot for your time.
There are references to getting these to work together, but these seem to be for RC, not IDE - (http://wiki.openqa.org/display/SEL/flowControl) recommends:
if( htmlTestRunner.currentTest.initialiseLabels ) { htmlTestRunner.currentTest.initialiseLabels();
})
When running the test in IDE there is no htmlTestRunner.currentTest.initialiseLabels.
Is there an IDE equivalent reference I can use?
Thanks!
Brian
Anonymous, check openqa.org for intros and tutorials.
I'll keep searching. Thanks,
Brian
Brian
would someone tell me where the default commands in selenium ide are stored? if at all i have to modify them, how do i go about it?
thanks.
would you tell me how can we generate random numbers in seleium IDE. actually I want to create unique Mail Id's to test a site. and give me an example of For loop in selinum IDE..
Regards
Suruchi
If you haven't found a solution already, you'll just need to run a javascript statement to generate the random number. There's not Selenium command for it, per se. You can use eval or storeEval though, with the random-number generating script as a paramter.
cheers,
Darren
This was a great extension but we are trying to implement our test cases in selenium-rc and we are wondering if it is possible to use the while loops and gotos still. Please let us know if this is possible.
When I store javascript{category} cat
I can then reference the variable and add additional text to it like this:
${cat} is the description of this item
But if I use getEval category=categoryName[index], as in the example, it won't resolve the variable and I get this:
javascript{category} is the desc...
Interesting and I'd love to know why.
If you haven't announced the license yet, might I ask that you do it under GPL, CC-SA, LGPL, Apache or something else that's compatible with the Selenium codebase and which also allows commercial use. The latter's important because of course most testers don't just test websites for fun; they do it for money too!
Thanks for the useful script!
Sam
"missing = in XML attribute"
in the IDE
FWIW, this is exactly what you get on startup of selenium IDE if you blindly save the script directly with right click "Save link as" rather than following the link and cutting and pasting into a fresh .js file, since it is wrapped in html blurb due to google docs.
Dumb, but caught me out.
I tried to load this add-on, but got the following error message:
Failed to load user-extensions.js!
files=/root/my-documents/selenium automation files/goto_sel_ide.js
lineNumber=103
error=SyntaxError: missing ; before statement
Could my OS (Puppy linux) be the problem?
i.e.
testcase1
label l1
gotoif true l2
testcase2
label l2
would testcase1 jump over to testcase2? I'll be testing this theory shortly, but thought I'd ask. I'll post my results.
myk
i have gone through all the blogs...
i have been using selenium from since 5 days and i have a query when i try to execute the html suite from rc i get the following error
The error message is: No while statements found
i have generated a data driven script using while loop
Problem is that I'm getting error msg while using 'gotoIf'.
Error msg:
[error] Unexpected Exception: message -> Specified label 'male' is not found., fileName -> chrome://selenium-ide/content/tools.js -> file:///E:/Salanium%20IDE/goto_sel_ide.js, lineNumber -> 81, stack -> Error("Specified label 'male' is not found.")@:0 ("male")@chrome://selenium-ide/content/tools.js -> file:///E:/Salanium%20IDE/goto_sel_ide.js:81 ("1<5","male")@chrome://selenium-ide/content/tools.js -> file:///E:/Salanium%20IDE/goto_sel_ide.js:90 ("1<5","male")@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 ([object Object],[object Object])@chrome://selenium-ide/content/selenium/scripts/selenium-commandhandlers.js:310 ()@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:112 (21)@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:78 (21)@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 , name -> Error
I'm using following code:
Open|http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_label
store|1|var_no1
gotoIf|${var_no1}<5|male
Would you please help me to get the issue resolved?
"Failed to load user-extensions.js!
files=D:\abcdefg\Automation\Selenium tool\datadriven\goto_sel_ide.js
lineNumber=103
error=SyntaxError: missing ; before statement". Please reply....
I am very new to Selenium IDE and have just figured out some basic and created simple tests. I need to do multiple iterations by passing different value to a particular field on the page. I am not sure how this can be done by using a file. Please guide me through.
At the top of the Selenium goto post you mention two extension files (one for RC/test runner, the other for IDE only). However, I see a link to only one file. Maybe I missed something?
BTW, nice pics at the top of your blog. I sail a Laser near San Francisco, and my son sails an Opti (http://www.blakeelder.com/opti-sailor/). That's a pretty sloop you have.
Thanks much!
Blake Elder
Thanks. My version of the script is a hacked version of the original that you can find on openqa.org. The original one works in Selenium RC and TestRunner but I needed something to use in Selenium IDE (the Firefox plugin), so I ported it over. Unfortunately my version doesn't work with both RC and IDE.
cheers,
D
I need urgent help regarding 2 things:
1. Is there a way i can parameterize my values for a script and run the scripts for multiple rows as provided by the Parameters/DataTable concept in QTP.
2. How can i create a batch script for a specific test case and a test suite.
In Selenium IDE I can save and open later individual test cases but not test suite. What I did before:
1) I click on Record and ran test scripts.
2) Save it as Test Suite (html format)
3) Opened SIDE 1.0.7 and File >Open Test Suite --> no Command list display
I have also tried to open New Test Suite before and create scripts and save them under the Test Suite with the same result >> NO COMMAND list displays.
Please help.
Thank you!
Alex.
I am a little stuck in using the flow control in IDE. Any help will be appreciated.
I am trying to use it to check if a user is logged in to the website or not. If logged in then click on the link 'Sign Out' and then carry on with the test. If link 'Sign Out' is not present then it should carry on with the test as normal.
First I am running storeLocation|activeURL
this stores the URL.
The I am trying to use the following:
gotoIf | '${activeURL}'!='${baseURL}${indexPage}' | Sign Out |
now the label I am using here is the 'Sign Out' link. I learnt that i have to specify the label using the command 'label|Sign Out', before I can use it in the gotoif. Why do we do this and how can I use the label name? In my case the 'Sign Out' is a link and not a label. How do I specify the target location so that it clicks on 'Sign Out' when the activeURL does not match the storedURL (${baseURL}${indexPage} in this case).
If I specify the variables as:
gotoIf | 'storedVars['activeURL']'!='storedVars['baseURL']storedVars['indexPage']'; | Sign Out |
it gives me a message saying "Unexpected Exception: message -> missing ; before statement"
I hope I made sense.
Thanks in advance..
Manav
Your question doesn't seem to be related to flow control. Visit the openQa forums for questions on using Selenium in general.
The goto label command will make selenium jump to the line with that label. It doesn't perform any actions at that line. It simply continues running the test case starting on the next line after the label. Which, in your case should be a click link command.
I really appreciate all the help.
I recently started using the S-IDE client to verify links on my website.
I've tried implementing the techniques you've suggested, but keep getting the following error-
[error] Unknown command: 'while'
It seems that selenium doesn't recognize my while statement.
while | storedVars['index'] < storedVars['linkCount']
Every time I run the test, I get stopped at this step. It might be because I have stored all the link on the page into an array incorrectly.
Any suggestions to what might be happening?
Thanks a lot!
-Carson
It looks like you might not have loaded the extension properly. Otherwise, the while instruction would be recognized. Check the illustrations for comparison.
I need a help on using a WHILE loop. In my application we have more than 60 links and I want to click on all those links using WHILE
May i know how you use If condition in case -
If logout link exits then click on the logout else click on the login link.
I am trying to use gotoIf, but could not get it working.
Please help!
Cheers,
DB
I get the error :
Unknown command: 'gotoIf'
when i run the script from the command line as:
"C:\Program Files\Mozilla Firefox\firefox.exe" -chrome "chrome://selenium-ide-testrunner/content/selenium/TestRunner.html?baseURL=http://localhost&test=file:///C:\new.html&auto=true&resultsUrl=http://localhost:8080/results.html&save=true"
I have the user-extensions.js on the same folder with the suite
When i run the script from the bowser it is working ok.
Any help is highly appreciated
if( this.initialiseLabels )
{ this.initialiseLabels(); }
at the end of doEnd$Template$ so that goto's after includes work.
I am wondering if you can clarify the solution for getting flow control and includes to play nice in the Selenium IDE... I have been pooring through forums all afternoon and am having trouble figuring out what I change where. Is there a way to get a download of the include extension that works with flow control in the IDE?
Any clarification would be much appreciated!
Gabe
Your posts on Selenium IDE have given lot of info. Thanks!
I am trying to loop through all links[around 200] in one webpage and see if each page has any errors. I use storeAllLinks which returns all Link ID's though when I want to loop through each I am unable to access each ID to be able to make it to click. Any inputs would be of great help!! Thanks
Mac OSX 10.6.6
Firefox 3.6.13
You must be logged into https://www.facebook.com/ and have the always use SSL when possible account option selected for this to work.
This is to remove old Facebook events and (WARNING) is probably against their terms.
testCase:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.facebook.com/" />
<title>facebook-remove-event</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">facebook-remove-event</td></tr>
</thead><tbody>
<tr>
<td>while</td>
<td>true</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/?sk=pe</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=#contentArea li:first a</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Remove from My Events</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>remove</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>remove</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
LOG:
* [info] Executing: |while | true | |
* [info] Executing: |open | /?sk=pe | |
* [info] Executing: |clickAndWait | css=#contentArea li:first a | |
* [info] Executing: |click | link=Remove from My Events | |
* [info] Executing: |waitForElementPresent | remove | |
* [info] Executing: |click | remove | |
* [info] Executing: |endWhile | | |
* [error] Unexpected Exception: message -> Invalid row_num specified., fileName -> chrome://selenium-ide/content/tools.js -> file:///Users/example/Documents/Selenium/selenium-ide-flow-control.js, lineNumber -> 62, stack -> Error("Invalid row_num specified.")@:0 (-1)@chrome://selenium-ide/content/tools.js -> file:///Users/example/Documents/Selenium/selenium-ide-flow-control.js:62 ("","")@chrome://selenium-ide/content/tools.js -> file:///Users/example/Documents/Selenium/selenium-ide-flow-control.js:100 ("","")@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 ([object Object],[object Object])@chrome://selenium-ide/content/selenium/scripts/selenium-commandhandlers.js:310 ()@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:112 (2)@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:78 (2)@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 , name -> Error
I wouldn't be surprised if a good number of people are using Selenium to automate actions on third party sites, but you do have to be careful not to violate terms of use, which I'm SURE we all are! ;-)
Thanks for posting the issue, and by the way, I'll be moving the source file over to github shortly, where it should become a lot easier to pull in patches.
thank you for your post.
Very usefull :)
BR
I have selenium IDE 1.0.10 and having added the plug-in and restarted the Selenium IDE. I encountered the following exception -
"error loading Selenium IDE extensions: ReferenceError: Selenium is not defined"
Not sure if it is because of selenium IDE version which I am using but this is the latest version available SeleniumHQ -
http://seleniumhq.org/download/
Please use the above script linked to on my github page. I understand a plugin was made from this script. If you're having an issue with that plugin, you'll need to follow up with it's maintainer.
I have downloaded the .js file and saved in my disk then i have included the path in the selenium core extension. Then i reopened and
started testing.
without any conditional command it is working, but when i use while command, and execute my test cases then the entire test cases are not running.(i.e) when i press the play button it is not at all running.Please May i know what is the reason for this.
What OS, Browser version and S-IDE versions are you using? BTW, you can head over to my Github page to get help with issues.
cheers,
Darren
My browser version is 3.6.16
OS-XP service pack 2
selenium ide-1.0.10
I've tried the next case on Selenium IDE.
store | 0 | i |
store | 6 | countryCounter |
while | storedVars['i']<=storedVars['countryCounter'] | |
getEval | storedVars['i']=${i} + 1; | |
echo | ${i} | |
endWhile | | |
I exepect 'echo' will prints a numbers 1-6.
Unfortunately it doesnt work. Stop executing on 'while' command with succes and commands in while block do not executing.
what is wrong?
will be very appreciated you for help.
Here is the original posting:
getEval | delete storedVars['myarray']
storeEval | new Array('a','b','c') | myarray
store | 0 | x
while | storedVars['x'] < 3
getEval | alert(storedVars['myarray'][storedVars['x']])
getEval | tmp = storedVars['x'];tmp++;storedVars['x']=tmp
endWhile
The biggest challenge was getting getEval to work. It is not offered as one of the commands in the Selenium IDE. runScript is the equivalent I found. I have not looked at the Selenium RC (or what is now called the Selenium Server). In any case, I got the equivalent example to work as follows:
storeEval | new Array('a','b','c') | myarray
store | 0 | x
while | storedVars['x'] < 3
runScript | javascript{alert(storedVars['myarray'][storedVars['x']]);1;} | 1
runScript | javascript{tmp = storedVars['x'];tmp++;storedVars['x']=tmp;}
endWhile
Note the use of javascript (referenced in post dated July 10, 2009 5:34 AM). I have needed to use that together with runScript.
Note also the trailing 1; in the javascript alert message and the 1
in the value field. Without that, the Selenium IDE shows the alert box - then logs the following type error:
[error] Unexpected Exception: message -> eval(match[1]) is undefined, fileName -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 2530, stack -> ("javascript{alert(storedVars['myarray'][storedVars['x']]);}")@chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js:2530 ()@chrome://selenium-ide/content/selenium-core/scripts/selenium-executionloop.js:109 (0)@chrome://selenium-ide/content/selenium-core/scripts/selenium-executionloop.js:78 (0)@chrome://selenium-ide/content/selenium-core/scripts/htmlutils.js:60 , name -> TypeError
I believe the evaluation of the javascript result is being compared with the value field and a type mismatch is reported with just the alert (without the 1;) and the value field being left blank.
One last note to the newbie:
to download sideflow, from the Firefox browser, when I clicked on https://github.com/darrenderidder/sideflow and then right clicked on sideflow.js and then Save Link as, the sideflow.js itself did not get saved but sideflow.js.htm. This however is not the sideflow.js javascript and not surprisingly, the
extension would not work (for instance, while would not be offered in the list of commands in the IDE). I had to click on the sideflow.js link at https://github.com/darrenderidder/sideflow and then copy and paste the javascript form the browser to a text editor and save as sideflow.js
The extension is okay, but I updated the demo test and the image in this post to show the "new" Selenese commands. getEval has been deprecated, and you now have to use the "store" command with some funky casting instead of accessing "storedVars" directly. I never really liked accessing Selenium internals directly, so this is better now.
cheers
Darren
Thanks for the comments. I updated the demo test. Also, for downloading and working with github code repos, I'd definitely recommend using "git" or one of the graphical git clients. Github <3 git!
cheers,
Darren
-Cheers
Andrey Yegorov is the original author of Selenium RC flow control; I merely ported it to the Selenium IDE plugin. Appreciate your comment, though.
Output code:
// selenium.Label("This is a test");
// selenium.Goto("label1");
// selenium.Label("label1");
String x = "1";
// selenium.While("${x} < 10");
// selenium.Label("loop");
// selenium.GotoIf("${x}==5", "got5");
// selenium.EndWhile();
// selenium.Goto("end");
// selenium.Label("got5");
// selenium.Goto("loop");
// selenium.Label("end");
cheers
Darren
I had installed the plugin for Selenium IDE Flow Control
Extension.from: https://github.com/darrenderidder/sideflow
and restarted the firefor version5.
then when i started IDE the gotoIF command was available for use. I
did used it also. but when I exported the Code as c#(Remotecontrol)
format.and opened it in Microsft visual studio 2010. All the gotoIF
statements are not recognized by the Microsft visual studio 2010. all
statements are commented out.
and
code looks like this when opened in studio:
selenium.Click("css=input[type=submit]");
Boolean TP = selenium.IsTextPresent("User name already exists");
System.Threading.Thread.Sleep(sleeptime);
// selenium.GotoIf("${TP}==false", "target1");
System.Threading.Thread.Sleep(sleeptime);
// selenium.Label("target1", "UseName");
System.Threading.Thread.Sleep(sleeptime);
How can i fix this issue?If i remove the comments// then it says: you
are missing a directive or assembly reference.
And if i try to add reference to the sideflow.js file it is not
detected.because it is not a .DLL file.
Anyone knows how to fix this?
Someone needs to patch the various code exporters to support the flow control commands, I guess. Really they should have been part of the core, but they're not. And that probably means you won't be able to export the control flow commands to C# without some tinkering in the Selenium source code itself.
Darren
I am using selenium command Gotoif in Firefox Selenium IDE, and could able to run test suite, but when run the same test suite with selenium RC it fails showing "unknown command gotif" is there any way to solve this problem, selenium ide 1.1.0 version and jar for for selenium server is "selenium-server-standalone-2.0.0.jar"
can some one suggest how to solve this problem or i am doing any thing wrong
Thanks & Regards,
Sairam
There is a flow control plugin for Selenium RC. You will need to use that in Selenium RC. It can be downloaded from the Selenium website, which lists plugins for Selenium RC. The flow control syntax should be identical.
Darren
But i could not find the plug in for Selenium RC what ever the plug in it has it was for Selenium IDE,
Request you to provide the link, or path where it exists,
Thanks & Regards,
Sairam
I've updated the article with a link to the original flowControl plugin for Selenium RC.
cheers,
Darren
I have a scenario where I need to click on a link in the dynamically created row.
1. Create a new user.(e.g., Testuser)
2. In the home page, the users are listed but the list is not sorted.
3. Now I need to click on delete link in row. After adding the new user, the page looks like below.
Newuser Edit Delete
Testuser Edit Delete
Realuser Edit Delete
The Delete link has ID which is GUID and none of the link's attribute contain Testuser.
Now, how to delete Testuser by clicking the delete link present in the same row?
Thanks in Adv
You can do that with XPATH. XPATH is a pretty broad topic in itself. You can get started using Firebug to look up the XPATH syntax for the element you want to select, although in your case you'll probably need to modify it to reference the element that contains the "TestUser" text.
Hope that helps.
Darren
Yes I did it. Thanks a lot for your suggestion
Cheers
Jay
I am new to Selenium, and to this extension, but i cannot find anywhere on the net some explanations about how it works. Can you please give me some details, or direct me to the correct place.
What does "label", "gotolabel", "gotoif", "while" ? And how it works ? Just need to understand the principle behind.
Happy reading!
Failed to load user-extensions.js!
files=/home/bla/data/selenium_extension/sideflow.js
lineNumber=6
error=SyntaxError: missing = in XML attribute
Currently it doesn't work with Firefox 7. Any plans to update it?
Regards,
Simon
On my Firefox 7 / Ubuntu setup it does work, but the "runScript" command fails with the sample test case. By replacing "runScript" with "getEval" everything works again.
Thanks for the heads up, not sure what is going on here exactly but will look into it and patch up the testcases as needed on github.
Darren
When I used the link below it refused to let me add it.
https://addons.mozilla.org/en-US/firefox/addon/flow-control/
I'll just add the javascript reference instead.
I've a problem with selenium IDE.
So I must to some names from the page and put them into the array.
I take them from the page without any problems by storeText|xpath=//div[@id='main']/div[3]/ul/li[${i}]
but don't know how to put them into the array.
Help please.
I have a such problem: I take some names from the page by
while|condition
storeText|locator|variable
but I can't to put them into the array.
Help me please.
I work with selenium IDE.
tdata>
lol
I used "storeXpathCount" but did not get the correct answer.
Please help me in getting the same.
Using Base URL http://www.tizag.com
open /htmlT/tables/php
storeXpathCount /html/body/table[3]/tr rows
getEval alert(${rows})
All I get is "Unknown command: 'if'".
I've been searching for hours and hours and hours to no avail - please help before I go insane!
Is it maeant to be part of Core or via a User Extension?
Have you ever attempted to add this feature? Any ideas in terms of level of effort? - Thank you!
I downloaded sideflow and placed the file path in options. However, I'm such a novice I am at a "Now what" moment.
I have an asp app that has dynamic buttons. If the Expand button (id=submit8)is pressed, the page sections expand and the Collapse button (id=submit9) is displayed in the same place.
Likewise, when the Collapse button (id=submit9)is pressed, the page sections collapse and the Expand button (id=submit8) is displayed.
I need the test to evaluate the the button and if the Expand button (id=submit8) is displayed, press it; otherwise goto the next command.
Can I do this with sideflow? If so, how best to format the test?
Thanks in advanced,
Jake
I think you should definitely be able to do what you're describing. The trick will be to figure out the condition for the gotoif command. I think you will just need to make sure that the button is present and visible. It depends on how your page is structured and whether the buttons are dynamically added and removed from the DOM or merely hidden. To start out you can try recording a simple test case by right clicking on the buttons and using Selenium IDE's built-in assert commands. The resulting test case should give you some ideas about how SIDE identifies the elements in question. You can also use Firebug and/or FIrepath to figure out the XPATH for the elements in question and use that to identify the buttons in your test case. Evidently Selenium also now supports CSS selectors, which most people find a lot easier to use. Anyhow, some combination of CSS selector, gotoif and voodoo magic will undoubtedly lead to success...
I can’t figure out why the last two lines are false. I think they should be true.
Using the datadriven extension:
SSNNeeded = “1”
echo javascript{storedVars.SSNNeeded=="1"} gives true
echo javascript{storedVars.SSNNeeded}
gives 1
gotoIf b=(storedVars.SNNNeeded=="1") next gives false
echo javascript{b}
gives false
Please advise me.
Thanks & Regards.
Ravi Teja
It depends on what you're trying to do. Generally, if you need flow control for you test case, it should be obvious. In your case, you can probably just select items serially, performing validation after each selection. Iteration makes sense when there is variability in the data set or you don't want to keep repeating the same commands manually.
Darren
I am unable to download the Sideflow extension. Is it not a free download?
[error] Unknown command: 'while'
I downloaded the file from github.. and nothing..
-----------
Failed to load user-extensions.js!
files=C:\Users\eh\Desktop\sideflow.js.htm, C:\Users\eh\Desktop\sideflow.js.htm
lineNumber=4
error=SyntaxError: missing = in XML attribute
-----------
Can this error be resolved? How?
I am using Selenium IDE 1.10.0 as well in the most recent version of Firefox (18.0) but running Ubuntu 10.04.4
Also downloaded the file from github. Just in case, I'll denote that I tried the demo file and that didn't work either, which wasn't surprising for me as none of the sideflow specific commands have been working.
Is there a FlowControl version which works with Selenium RC 2 (added as an extension in start cmd)?
I get the test hang and in IE I have an error about testCase which is not defined.
Any ideas?
[info] Executing: |while | ${index} < ${fVals}.length | |
[error] Unknown command: 'while'
first of all I'd like to thank you for the incredible amount of efforts you have put into your work to the benefit of quite a lot of people.
Now, here's my question.
As an exprienced tester and with some knowledge around scriptingand automation, I seem to got confused with all the IDE vs. core vs. RC vs. Webdriver talk in the Selenium microcosmos.
What I am looking for is a solution that allows me to do conditional flows and loops in Selenese and being able to use that while working inside the IDE as well as when the Selenese scripts are processd against the "standalone server".
What is the right selection of plugins, scripts, etc. and where/how do I have to install them?
From my understanding, when you say it is an extension of the IDE but needs to be installed as a core extension, I assume that it exactly does what I need:
Provide me with "functions" that will run both in the IDE as well as when used with the standalone server jar of Selenium.
TIA for any pointers, cheers,
Thomas
Selenium IDE settings has a place to add core extensions but sadly the original flow control extension did not work in Selenium IDE, which is why I needed to port it. It still needs to be added as a core extension in S-IDE; if you're running Selenium RC you need to use the original flow control extension. I'd like to support both but it just hasn't been a priority. Maybe somebody else would like to contribute code via GitHub for that? I doubt we will see flow control natively in Selenium because the original authors seem to think that flow control in test cases is just plain wrong. I don't think they envisioned a lot of the use cases people are doing with it today.
D
thanks a lot for the fast response!
My intention is to have easy-to-maintain scripts, as most of my peers are junior testers with almost no exposure to scripting, automation or programming. Selenese scripts are fine for that.
However, equally important is the reusability of the scripts in nightly runs, thus "unattended" mode to put it that way.
So far, what we are doing is to run the Selenese scripts (used in the IDE) against the "standalone-server" jar.
(I call it "standalone-server" jar because I have no clue if this is the "RC" or "core" or whatever name it was given... just making sure I don't mess up things.)
If I get you correctly, this means that a Selenese script that uses e.g. "gotoIf" will run just fine in the IDE but not when the Selenese is used for execution with the standalone-server jar?
Cheers,
Thomas
Now, after adding sideflow.js the GoToIf command is not shown. The test case fails on that step with [error] Unknown command: 'gotoIf'.
I've tried all kinds of variations, including goto_sel_ide.js. Is GoToIf and the sideflow.js just not supported in IDE 2.0.0?
I've parametrized all the variables. However, When I run it in from a batch file, I get a message stating: Threw an exception: AdminEmailAddress is not defined.
(tryin to enter an email add from the .js file)
It runs fine on firefox when I have selenium loaded and running, but only hit the problem when running the suite through a batch file.
Any help on this matter will be appreciated.
Regards
Regards
http://stackoverflow.com/questions/12537620/is-there-a-way-to-split-a-string-into-an-array-in-selenium-ide
Thanks
El Gato
I am learning Selenium IDE and have got to the flow control part. I couldn't make it work. Do you have any videos that might help me understand how this work? Thanks.
We typically use Selenium IDE to build our tests and run them in firefox. The we use webdriver to run our tests in chrome, IE and safari. I've seen that the flow control commands don't work in webdriver...is there a get around for this? Flow control has been really useful for us :) Thanks for all your hard work on this.
Ed
I'm getting a issue to use the "gotoIf" option.
How can I use it to jump to another line if a element is/isn't there??
What I'm doing is:
|storeText | id=formCadastroOfertaLance:data:0:j_id222 | lance |
[info] Executing: |gotoIf | "${lance}"=="Lance Livre" | label1 |
the problem is: when (...):j_id222 doesn't exist, I got an error and the script stops.
How can I do that "gotoIf" using as parameter if this element exists or not??
Although, if your application has scenarios where sometimes things are present and sometimes not, maybe it is too complicated. Or maybe you should have different test suites and not try to cover too many scenarios in the same test suite.
The target for my while command is "verifyElementPresent=['class=foo']", and this appears to always be true, despite all of the foos being removed from the page.
Is there a better way to terminate the while loop when the target is no longer present?
Thanks!
Assume: String 1 = This is test 40
I entered these scripts:
storeText | xpath... | tempValue
while | tempvalue != "glob*40"
....
The above doesn't work. I tried different synatx like glob"*40" glob*"40", ... but nothing works.
Without glob it works. So how do we do pattern matching with conditions?
How can I use as part of a stress test.
e.g. if we say touch of a button x times again and again and again in succession. a bit like if there were many users at once that did it.
I was trying to use "&&" and "|", are these implemented in IDE Flow Control because I'm not able to make them working. It's a pain in the ass to have to use two "if" instead of one that just meets two conditions using "&&", so I hope I'm doing something wrong but I can use them...
Thanks for your help.
We have an idea of what is happening:
There are two libraries for flowcontrol.
One works for Selenium IDE and the other one works for Selenium Server (but only running TestRunner.html not with RemoteRunner.html.
Is there any driver for flowcontrol that can works for Selenium RC ?