0

I am trying to use this devtools protcol command: Page.AddScriptToEvaluateOnNewDocument.

It seems that this protocol command is not fully implemented in the c# version of selenium. I also tried the click event too, but this didn't work as well. However, I was able to use one devtools command, a networking one with the code:

IDevTools devTools = driver as IDevTools;
DevToolsSession session = devTools.CreateDevToolsSession();
session.Network.Enable(new OpenQA.Selenium.DevTools.Network.EnableCommandSettings());
session.Network.SetBlockedURLs(new OpenQA.Selenium.DevTools.Network.SetBlockedURLsCommandSettings()
{
    Urls = new string[] { "favicon" }
});

Is there something I can do to fix this myself?

References:
https://github.com/SeleniumHQ/selenium/issues/8000

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Zanga
  • 55
  • 3
  • 11
  • It's implemented by the protocol itself which is why the cs file is just a dummy (same for the other commands), so I guess you've used it incorrectly. – wOxxOm Jun 07 '20 at 11:22

1 Answers1

0

Here is the correct code you can use:

using DevTools =  OpenQA.Selenium.DevTools.V95;

using Network = OpenQA.Selenium.DevTools.V95.Network;

using DevToolsSessionDomains = OpenQA.Selenium.DevTools.V95.DevToolsSessionDomains;


        IDevTools devTools = chromeDriver as IDevTools;
        IDevToolsSession session = devTools.GetDevToolsSession();


        var domains = session.GetVersionSpecificDomains<DevToolsSessionDomains>();
        await domains.Network.Enable(new Network.EnableCommandSettings());
        await domains.Network.SetBlockedURLs(new DevTools.Network.SetBlockedURLsCommandSettings()
        {
            Urls = new string[] { "favicon" }
        });
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Abhishek28
  • 11
  • 3