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.
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
// 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
// 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
// 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 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