How to use "storeAttribute" command in selenium
"storeAttribute" command stores the attribute value of specified element in given variable. You can store any attribute's value using "storeAttribute" command. You need to provide proper path of element node followed by an @ sign and then the name of the attribute (e.g. a@href . Here "a" is element's node name and "href " is
attribute name which we want to store) in target column of selenium IDE.
attribute name which we want to store) in target column of selenium IDE.
Bellow are couple of examples to understand "storeAttribute" command.
Examples of "storeAttribute" command
New Test | ||
Command | Target | Value |
open | http://www.google.com | |
storeAttribute | xpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@href | Myhref |
echo | ${Myhref} |
Look in to above example. "storeAttribute" command will store value of attribute 'href' in to variable = 'Myhref'. Here, "xpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a" is the xpath of node = a . Click here to learn how to write xpath of any element node. You need to provide proper path of element to get it's any attribute value. Bellow some more examples.
New Test | ||
Command | Target | Value |
open | http://www.google.com | |
storeAttribute | xpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@id | Myid |
echo | ${Myid} | |
storeAttribute | xpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@onclick | Myonclick |
echo | ${Myonclick} | |
storeAttribute | xpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@class | Myclass |
echo | ${Myclass} |
1st "storeAttribute" command will store value of attribute 'id' in to variable = 'Myid'.
2nd "storeAttribute" command will store value of attribute 'onclick' in to variable = 'Myonclick'.
3rd "storeAttribute" command will store value of attribute 'class' in to variable = 'Myclass'.
In this way, you can get any element's attribute value and use that value at stage of script.
hi, thanks for this useful post
ReplyDeletehow to implement same with webDriver
Hello! I've been following your blog for some time now and finally got the courage to go ahead and give you a shout out from Kingwood Texas! Just wanted to mention keep up the excellent work!
ReplyDeleteHere is my site - folks
thanks for this post
ReplyDeletegood post..........
ReplyDelete