Conditional comments bug fixes

Remove conditionals prior to locating the html element and handle
malformed conditionals (e.g. missing trailing ']')