I know the standard method of getting text from an element is using getText, but I was just curious to know that getProperty(id,“text”) throws an error instead of returning an empty string like getText, when accessing an element with no text.
This happens when trying to get text from a text label or a text area, doesn’t happen in buttons, dropdowns or text inputs.
Link to example
Any idea why?
Well from my guess is how the getProperty function is initiated, from my guess getText function is basically like getAttribute(id, “textContent”) which will return the correct property you can use this or “innerHTML” if your feeling fancy but if your real question i can’t quite answer fully but… I’ll give you my running theory
so basically calling get property will invoke a sandboxed function which will check if the element exists and what type of element it is… then it’ll cross reference all the available whitelisted “properties” listed within the element if it’s invalid you’ll get a pre-formatted error which would make our lives easy but no it’s not that which means you have to follow the function across multiple scripts
a bunch of jumping later you’ll find readProperty in design mode which test what the nodeName of the element is, as long as it isn’t text it’ll lead us to this function call escapeText(element.innerHTML) which then basically takes us to our final destination of utils.js where escapeText is and it’s performing a lot of regex and i mean a lot of it but that shouldn’t be an issue since the other elements also return basically the same text from innerHTML which leads me to believe that the error is how the approach is for parsing text for those two elements are, you can see what it in more detail when running in the web console
And since CDO is open source i took the liberty of getting those files referenced from the repo they’ll be included below
Applab > getProperty()
Applab > readProperty()
Applab > designMode > readProperty()
Applab > utils > escapeText()
If anyone is able to figure anything further let us know in the thread!