I'm not sure what you are trying to do. Are you trying to get the text before "kg" or are you trying to return
true or
false depending on whether the text contains the "kg" word or not?
If you are trying to get the text before "kg" perhaps
this post will help. Note that the code posted there is case sensitive, which means you will either need to use "Kg" or "kg". To use both you can just change this line in the JavaScript gatherer:
for this:
Code: Select all
text = element.innerText.toLowerCase();
and then use just "kg" since if there is a "Kg" it will be converted to "kg" because of the call to
toLowerCase().
Also, a note about your code, you are not using the
element parameter in it. A JavaScript without it doesn't make any sense because the function of a JavaScript gatherer is to return some information about the element. The element is a parameter passed to the JavaScript gatherer that contains an HTML element. For instance, if you would like to write a gatherer that gets the text of the element, this would be the code:
This is not necessary though, because there is already a built-in property gatherer that does that called "InnerText". But if you would like, for instance, to get the text of the element but as lower case, you could do this:
Code: Select all
return element.innerText.toLowerCase();
I hope this help clarifying how JavaScript gatherers work.