I'm trying to read an HTML element's aria-label attribute using IE's getAttribute
method in C++/COM but although this works fine for other attributes (including aria-labelledby) it returns VT_NULL for aria-label.
My code example looks like this:
CComVariant label;
elem->raw_getAttribute(CComBSTR(L"aria-label"), 0, &label);
if (label.vt == VT_BSTR && SysStringLen(label.bstrVal)) {
// This is never reached
}
I get the same results when using 2 for the flags
argument of getAttribute
.
Sample HTML here.
When I try using getAttribute
in JavaScript in the browser this works perfectly but for some reason I can't reach this attribute using COM.
Am I missing something here?
In my experience, some new new HTML5 attributes are accessible via DOM Level 3 getAttributeNode
method (available in IHTMLElement4
).
E.g., to make it work for placeholder
attribute, I had to use WebBrowser Feature Control and enable HTML5 for the web page with <!DOCTYPE html>
and <meta http-equiv="x-ua-compatible" content="IE=Edge"/>
(which is a good idea in either case).