ExecuteScript(document.getElementById('form') in Webview2(C++) return null or some jQuery like string

171 Views Asked by At

I'm used webview2 executeScipt to access DOM but have some issue.

html document is loading completed and then below c++ code called. only getElementById function not working, return null, but outerHTML is well.

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <div id="internalWrapper">
    <div id="container" class="lightTheme">
    <div id="form_header"></div>
    <div id="form" ctrltype="CT_FORM" class="formGrid" container="true"></div>
    <div id="form_footer"></div>
    </div>
    </div>  
</div>
</body>
</html>
webview->ExecuteScript(_T("document.documentElement.outerHTML", hCallback) // OK, return full html code 
webview->ExecuteScript(_T("document.getElementById('form')", hCallback)    // return null  

I changed html file to very simple html and changed api to getElementByClassName() but return null.

0

There are 0 best solutions below