06-18-2017 12:41 PM - edited 06-18-2017 01:41 PM
Im having touble extracting text from an html page using XPath. This is just an arbitrary example of a bigger problem I'm trying to solve.
In the attached HTML I'm trying to extract the text 600396 from.
<td id="a"><a href="/Home/Contact">600396</a></td>
My script shoud print the extracted value to the event long and set a it to a custom property. When I test my XPath it seems to be working but when I run the script it only returns an "H" which I though was strange, it turns out its returning the entire html document in a string array. If I remove the Index selector from my the query , getResponse() just returns the entire html document.
var msg = $context.currentItem.previousItem.children
var query = msg.getResponse(msg.HTTP_BODY_AS_HTMLL, '//*[@id="a"]/a');
$prop.set("MessageClip", "clipProp", query);
I'm brand new with this, any help is appriciated.
Solved! Go to Solution.
06-18-2017 05:21 PM
You should try to be more specific with your XPaths though I know your example is generic in an effort to understand what's amiss. Using index references within an XPath makes them fragile and subject to invalidation if anything changes.
For your example you would use something like //*[contains(@href,'Contact')]/text() Typically there is a class and name that will distinguish the XPath and you can use something like //*[@class='specific name']/text() or //*[@class='specific name']/@href
This can all be done in a property extraction and it looks like you're trying to do it via JS instead. Doing it via a property will simplify the process dramatically unless there is a specific need for a JS in this instance.
06-19-2017 01:16 PM
Not a problem. Let us know if you run into anything else and feel free to check out the videos on how to do a number of different things within CloudTest. The link is in my signature below.
© 2015 SOASTA. All Rights Reserved. Privacy & Legal