selenium "storeCssCount" and "verifyCssCount" Commands with Example

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.

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
CommandTargetValue
setSpeed500
openhttp://www.wikipedia.org/
storeCssCountcss=formNoOfForms
echo${NoOfForms} no of form nodes
storeCssCountcss=fieldsetNoOffieldsets
echo${NoOffieldsets} no of fieldset nodes
storeCssCountcss=inputNoOfinput
echo${NoOfinput} no of input nodes
storeCssCountcss=input[id]NoOfinputID
echo${NoOfinputID} no of input nodes with 'id' attribute
storeCssCountcss=input[type]NoOfinTYPE
echo${NoOfinTYPE}no of input nodes with 'type' attribute 
store6MyCount
echo${MyCount}
echo${NoOfinput}
gotoIfstoredVars['MyCount']!==
storedVars['NoOfinput']
Not Match
labelChangecount
store9MyCount
verifyCssCountcss=input[type]6
verifyCssCountcss=input[type]9
gotoIfstoredVars['MyCount']==
storedVars['NoOfinput']
Match
labelNot Match
echoExpected CSS count '${MyCount}' did not match with actual CSS count '${NoOfinput}'.
gotoLabelChangecount
labelMatch
echoExpected 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'.

1 comment:

  1. gotoIf command is not available in selenium IDE please let me know

    ReplyDelete