I was able to invoke Chrome Remote Interface functions inside Selenium WebDriver session (Page.captureScreenshot, Emulation.clearDeviceMetricsOverride etc). But I have problem with invoking methods which work on DOM element. The problem is with nodeId parameter. For example this function https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setFileInputFiles accepts as one of parameters nodeId. I can't figure out how to extract nodeId based on IWebElement (or RemoteWebElement) from SeleniumWebdriver.
How can I find nodeId using Selenium or Javascript?
More info about Chrome Remote Interface could be found here https://chromedevtools.github.io/devtools-protocol/
I found the answer asking on devtools-protocol issue tracker here https://github.com/ChromeDevTools/devtools-protocol/issues/66
The full working solution could be found here: https://github.com/cezarypiatek/Tellurium/blob/master/Src/MvcPages/SeleniumUtils/ChromeRemoteInterface/ChromeRemoteInterface.cs
private long GetChromeNodeId(IWebElement inputElement)
{
driver.ExecuteScript(@"(function(fileInput){
window.__tellurium_chromerinode = fileInput;
})(arguments[0])", inputElement);
var evaluateResponse = SendCommand("Runtime.evaluate", new Dictionary<string, object>
{
["expression"] = "window.__tellurium_chromerinode"
});
driver.ExecuteScript(@"(function(fileInput){
delete window.__tellurium_chromerinode;
})()");
var remoteObjectId = evaluateResponse.GetValue<string>("result.objectId");
var rquestNodeResponse = SendCommand("DOM.requestNode", new Dictionary<string, object>
{
["objectId"] = remoteObjectId
});
return rquestNodeResponse.GetValue<long>("nodeId");
}