# How to get nth attribute of a page element

**URL:** <https://forums.eggplantsoftware.com/t/how-to-get-nth-attribute-of-a-page-element/3842>\
**Category:** Eggplant Functional\
**Tags:** atrributes, xpath, selenium, eggplant-functional\
**Created:** [March 13, 2019, 4:49pm UTC](https://forums.eggplantsoftware.com/t/how-to-get-nth-attribute-of-a-page-element/3842 "2019-03-13T16:49:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mayuri](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/m/278dde/32.png) [@Mayuri](https://forums.eggplantsoftware.com/u/Mayuri)\
**Post date:** [March 13, 2019, 4:49pm UTC](https://forums.eggplantsoftware.com/t/how-to-get-nth-attribute-of-a-page-element/3842/1 "2019-03-13T16:49:51Z")

</div>

I’m trying to get data of an element’s second attribute. For example, I have something like this: \<div **class** = “XYZ” **data-json** ="{ “componentname”:“ABCD”,“ **orderID** ”:“1234”,…}“  
I need orderID from the above page element.   
  
I tried the following:  
  
put FindElement(WebXPath:”//\*[@id=‘main’]/div[2]/div")'s “data” & numToChar(45) & “json” --\> Throws an error that DATA-JSON property isn’t found.

---

<div class="post-metadata">

**Author:** ![Mayuri](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/m/278dde/32.png) [@Mayuri](https://forums.eggplantsoftware.com/u/Mayuri)\
**Post date:** [March 14, 2019, 4:57pm UTC](https://forums.eggplantsoftware.com/t/how-to-get-nth-attribute-of-a-page-element/3842/2 "2019-03-14T16:57:57Z")

</div>

This is the working solution I could figure out:  
  
// Get the page source of the current webpage and set it as an XML tree  
 put the webdriver's **pageSource** as tree into x  
  
// Traverse through the tree to reach the tag you have the attribute you are looking for

 put item 3 of node "\*" of x into body

 put item 1 of item 2 of item 11 of item 1 of node "\*" of body into bodytags  
  
// get the data-json attribute from the tag. "data-json" isn't recognized directly so I have used ASCII value

 put bodytags.("data" & numToChar(45) & "json") into gotJson  
  
// My order ID is the 5th json value of the whole json response

 put item 5 of JSONValue(JSONFormat(gotJson)) into gotOrderID  
  
// Split the order ID by " : " and " " ". Again, use ASCII values when eggplant can't recognize certain characters

 split gotOrderID by ":"

 split second item of gotOrderID by **numToChar(34)**

 put second item of second item of gotOrderID into salesforceID
