ChromeDriver ExecuteCdpCommand 中的参数无效

问题描述 投票:0回答:1

我正在尝试使用 CdpCommand 并在 Network.setBlockedURLs 中设置参数(https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-setBlockedURLs), 但我得到了例外,尽管我把一切都设置好了。怎么了?

“OpenQA.Selenium.WebDriverArgumentException:”无效参数:无效参数 (会话信息:chrome=126.0.6478.114)""

        ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(@"C:\");
        chromeDriverService.HideCommandPromptWindow = true;

        ChromeOptions opts = new ChromeOptions();
        opts.PageLoadStrategy = PageLoadStrategy.None;

        Proxy proxy = new Proxy();
        proxy.Kind = ProxyKind.Manual;
        proxy.IsAutoDetect = false;
        proxy.SslProxy = ip_string;
        opts.Proxy = proxy;

        driver = new ChromeDriver(chromeDriverService, opts);
        chrome_id = chromeDriverService.ProcessId;

        var blocked_resources = new Dictionary<string, object>
        {
            { "urls", "analytics.google.com" },
            { "urls", "*.js" }

        };


        ((ChromeDriver)driver).ExecuteCdpCommand("Network.setBlockedURLs", blocked_resources);
c# selenium-webdriver selenium-chromedriver
1个回答
0
投票

根据 https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-setBlockedURLs,参数应如下所示:

{
"urls":["analytics.google.com", "*.js"]
}

而不是

var blocked_resources = new Dictionary<string, object>
{
    { "urls", "analytics.google.com" },
    { "urls", "*.js" }
};

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.