Selenium IDE "assertElementHeight" and "assertElementWidth" commands with examples

"assertElementHeight" and "assertElementWidth" are assertion commands and useful to verify and assert if expected height and with don't match with actual height and width of element on software application page. I posted article about "storeElementHeight" and "storeElementWidth" before and described how
selenium helps us to store element's height and width in variable. Height and width are measured in pixels.

"assertElementHeight" Command
"assertElementHeight" command will verify and compare actual height of targeted element with expected value(given in value field of selenium IDE). it will be pass and execute next command if both the value will match. Else, it will return error like "[error] Actual value '552' did not match '553'" and stop the execution.

"assertElementWidth" Command
Same as "assertElementHeight" command, "assertElementWidth" command will work with element's width. Let me give you one simple example for both the commands.

New Test
CommandTargetValue
openhttp://www.google.com/
storeElementHeightid=gbqfqi
echo${i}
storeElementWidthid=gbqfqj
echo${j}
typeid=gbqfqhello world
clickid=gbqfb
assertElementHeightid=gbqfq${i}
assertElementWidthid=gbqfq${j}
assertElementWidthid=gbqfq553
assertElementWidthid=gbqfq552

In above example, initially "storeElementHeight" and "storeElementWidth" commands will store Google search box's height and width in variables 'i' and 'j'.

  • 1st "assertElementHeight" command will compare actual height of Google search box with expected height (${i}= 19 pixels). It will be pass.
  • 2nd "assertElementWidth" command will compare actual width of Google search box with expected width (${j}=552). It will pass.
  • 3rd "assertElementWidth" command will compare actual width of Google search box with expected width (553). It will fail and selenium will stop execution.
You can use both the commands with any element of page of software web application like image, button, text area drop down etc..

2 comments:

  1. Hello sir,

    Its a great help, i need to ask is there a single command available in selenium IDE to verify the height or width of an element.

    ReplyDelete
  2. Hi aravind,

    Its amazing, thank you so much for your great post and help. I have one more question, is it possible to have width value in percentage (%), coz width value of header varies for different resolutions. I hope you got my query.

    Thanks,
    Abhinav Bajpai.

    ReplyDelete