Selenium IDE "verifyAttribute" and "assertAttribute" commands example

"verifyAttribute" and "assertAttribute" commands are useful for verification of values of an attribute of any node on the page of software web application. You can check value of an attributes like class, title, id, name, type, etc.. I got many questions about "Difference between assert and verify in selenium with example" so i will describe
that difference in this post too. Before using both these commands, You must have to read How to build XPath of an element and How to build CSS path of an element articles to be aware about it.

"verifyAttribute" Command
"verifyAttribute"  command will just check and verify the value of specified attribute. If found correct value on specified attribute then it will be pass and selenium software testing tool will execute next immediate command. If found incorrect value then selenium software testing tool will return error like "[error] Actual value 'search' did not match 'search1'" and will execute next immediate command.

Note : You can take a full course of selenium IDE (Free of charge) to be master in just 7 days.

"assertAttribute" Command
"assertAttribute" command works same as "verifyAttribute"  command but only one difference between "assert" and "verify" in selenium is - if "assert" command will fail then selenium software testing tool will not execute next command(stop execution) and if  "verify" command will fail then selenium will execute next command(not stop execution).

Let me show you an example

New Test
CommandTargetValue
openhttp://www.wikipedia.org/
verifyAttributecss=input + input@idsearchInput
assertAttributecss=input + input@idsearchInput
verifyAttributecss=input + select@namelanguage
verifyAttributexpath=//div[2]@classcentral-featured
verifyAttributexpath=//input[@type='search']
@name
search1
assertAttributexpath=//div[2]@classcentral-featured
assertAttributecss=input + select@nameanguage
verifyAttributecss=input + input@idsearchInput

  • 2nd "verifyAttribute" command will locate the 'input' node using CSS path and look into it for attribute = 'id' containing 'searchInput' text. It will pass.
  • 3rd "assertAttribute" will check same thing and will be pass.
  • 4th "verifyAttribute" command will locate 'select' node and verify for 'name' = 'language'
  • Same way, 5th command "verifyAttribute" will locate element using xpath and verify 'div[2]' node for 'class' = 'central-featured'
  • 6th command "verifyAttribute" will be fail and return expected "[error] Actual value 'search' did not match 'search1'". [Note : Here selenium will not stop its execution because of "verify" command]
  • 8th command "assertAttribute" will return expected "[error] Actual value 'language' did not match 'anguage'" in log. [Note : Here selenium will stop its execution because of "assert" command so next command "verifyAttribute" will be not executed].
In above example, you clearly understand how to use and difference between assert command "assertAttribute" and verify command "verifyAttribute" in selenium  software testing tool. Post your query as a comment bellow this post.

5 comments:

  1. its very useful for new student

    ReplyDelete
  2. its very useful to new students

    ReplyDelete
  3. Really helpful for beginners.

    ReplyDelete
  4. I'm learning to automate an android app and have a specific scenario in which an user have to re-enter password after timing out for 2 mins. I need to enter password in the application anywhere if the screen somes up. Any suggestions to address this issue

    ReplyDelete