CSS element locators are very strong and important for not only selenium IDE but also for selenium RC, webdriver and all other versions of selenium. I suggest you to read my post about CSS Locators for selenium IDE first, where i described many different ways of writing CSS path for any node of page with
examples. Now let me describe 2 selenium commands related to CSS which will help you to count no of CSS locators on page.
examples. Now let me describe 2 selenium commands related to CSS which will help you to count no of CSS locators on page.
Selenium "storeCssCount" Command
"storeCssCount" command used in selenium IDE to store number of CSS count for targeted node in to variable. You can use this command when you need CSS count to use it in other commands like "verifyCssCount" or "assertCssCount" or "gotoIf" to compare the CSS count value to take some decision based on CSS count.
"verifyCssCount" Command in selenium
As described above, "verifyCssCount" command helps you to verify CSS count on page. Let me give you example for "storeCssCount" and "verifyCssCount" commands.
New Test | ||
Command | Target | Value |
setSpeed | 500 | |
open | http://www.wikipedia.org/ | |
storeCssCount | css=form | NoOfForms |
echo | ${NoOfForms} no of form nodes | |
storeCssCount | css=fieldset | NoOffieldsets |
echo | ${NoOffieldsets} no of fieldset nodes | |
storeCssCount | css=input | NoOfinput |
echo | ${NoOfinput} no of input nodes | |
storeCssCount | css=input[id] | NoOfinputID |
echo | ${NoOfinputID} no of input nodes with 'id' attribute | |
storeCssCount | css=input[type] | NoOfinTYPE |
echo | ${NoOfinTYPE}no of input nodes with 'type' attribute | |
store | 6 | MyCount |
echo | ${MyCount} | |
echo | ${NoOfinput} | |
gotoIf | storedVars['MyCount']!== storedVars['NoOfinput'] | Not Match |
label | Changecount | |
store | 9 | MyCount |
verifyCssCount | css=input[type] | 6 |
verifyCssCount | css=input[type] | 9 |
gotoIf | storedVars['MyCount']== storedVars['NoOfinput'] | Match |
label | Not Match | |
echo | Expected CSS count '${MyCount}' did not match with actual CSS count '${NoOfinput}'. | |
gotoLabel | Changecount | |
label | Match | |
echo | Expected CSS count '${MyCount}' match with actual CSS count '${NoOfinput}' |
In above example, command execution and results will be as bellow.
- 1st "storeCssCount" command will return number of nodes found on page where node name = 'form' and will store that value in variable 'NoOfForms'.
- 2nd "storeCssCount" command will return number of nodes found on page where node name = 'fieldset' and will store that value in variable 'NoOffieldsets'.
- 3rd "storeCssCount" command will return number of nodes found on page where node name = 'input' and will store that value in variable 'NoOfinput'.
- 4th "storeCssCount" command will return number of nodes found on page where node name = 'input' & attribute = 'id' and will store that value in variable 'NoOfinputID'.
- 5th "storeCssCount" command will return number of nodes found on page where node name = 'input' & attribute = 'type' and will store that value in variable 'NoOfinTYPE'.
- 1st "gotoIf" will send selenium pointer to label = 'Not Match' because Expected CSS count '6' will not match with actual CSS count '9' and then selenium pointer will jump on label = Changecount for verification of CSS count once again.
- 1st "verifyCssCount" command will return "[error] Actual value '9' did not match '6'".
- 2nd "gotoIf" will send selenium pointer to label = 'Match' because now Expected CSS count '9' will match with actual CSS count '9'.
gotoIf command is not available in selenium IDE please let me know
ReplyDelete