Why doesn't MSHTML for .Net have querySelector and querySelectorAll, or where are they?

前端 未结 2 812
小鲜肉
小鲜肉 2020-12-21 04:54

I want to use MSHTML [1] to access DOM in IE, but I have just found out that it lacks querySelector and querySelectorAll methods in HTML document classes, which will otherwi

2条回答
  •  一生所求
    2020-12-21 05:21

    Yesterday I notice the same problem, I found a solution.

    The Next example code works for me:

    Document.querySelectorAll("#navbar_search>a").item(0).click();
    

    If i try to do "the same", but with this code, it fails:

    HTMLDocument doc;
    doc = ie.Document;
    doc.querySelectorAll("#navbar_search>a").item(0).click();
    

    I'm not a COM expert but I thing the first solution is a late binding (dependences are resolved at run-time), while the second solution is a compliler-time binding and it depends on a 'good' predefined libary and that's not the case with mshtml.

提交回复
热议问题