Selenium "storeAttribute" example to store URL or any other attribute value of element node


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.


Bellow are couple of examples to understand "storeAttribute" command.

Examples of "storeAttribute" command


New Test
CommandTargetValue
openhttp://www.google.com
storeAttributexpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@hrefMyhref
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
CommandTargetValue
openhttp://www.google.com
storeAttributexpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@idMyid
echo${Myid}
storeAttributexpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@onclickMyonclick
echo${Myonclick}
storeAttributexpath=//body/div[3]/div[1]/div[1]/div[1]/div/ol/li[3]/a@classMyclass
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.

4 comments:

  1. hi, thanks for this useful post

    how to implement same with webDriver

    ReplyDelete
  2. 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!

    Here is my site - folks

    ReplyDelete