Is there any definite way to retrieve the xPath of a angleSharp IElement
I'm trying to pass an IElement to a javaScript function, so I need a way to convert the angleSharp element to a javaScript Dom element
function selectLevels(element, name, level){
document.querySelectorAll("*").forEach(e => {
if(e.isEqualNode(element)){
e.setAttribute('level', level);
e.setAttribute('title', name);
}
})
}
I want to call this javaScript function which is in the page by passing an element from the C# code bellow, but I get an angleSharp not found error from the page.
IElement element = mainDoc.QuerySelector("strong");
Page.ClientScript.RegisterStartupScript(this.GetType(), "SelectLevel", "selectLevels('" + element + "', '" + name + "', '" + level + "')", true);
If you have a HTML document with JavaScript code and want to call a (global) function in the JavaScript code from C# then the following example works for me with AngleSharp 0.15 and AngleSharp.Js 0.14:
So basically you get the function with e.g.
jsService.GetOrCreateJint(document).GetValue("selectLevels");
and call it with itsInvoke
method, passing in string arguments for the simple types and theIElement
converted withJsValue.FromObject
e.g.JsValue.FromObject(jsService.GetOrCreateJint(document), document.QuerySelector("section"))
.