【问题标题】:Getting network information with ChromeDriver in C#在 C# 中使用 ChromeDriver 获取网络信息
【发布时间】:2016-10-02 14:43:25
【问题描述】:

我正在尝试从使用 C# 中的 ChromeDriver 启动的 chrome 页面访问网络选项卡信息。

我希望至少传输的总数据量和页面加载时间...

我一直在设置不同的ChromeOptionsDesiredCapabilities,但几乎没有成功。到目前为止,我唯一要做的就是执行一个脚本并将结果转换为 long。

Convert.ToInt64(((IJavaScriptExecutor)ChromeDriver).ExecuteScript("return window.performance.timing.navigationStart"));

但是,如果可能的话,我不想这样做...提前致谢!

【问题讨论】:

    标签: c# selenium-webdriver google-chrome-devtools selenium-chromedriver chrome-options


    【解决方案1】:

    如果其他人将来看到这个,我会分享一些信息。因为我目前也遇到了开发工具的问题。

    如果您使用的是 4.0 alpha 如何与开发工具交互,则有来自 Selenium 的 official guide

    我将在这里分享我目前正在使用的片段。

    IDevTools devTools = driver as IDevTools;
    DevToolsSession session = devTools.CreateDevToolsSession();
    session.Network.ResponseReceived += ResponseReceivedHandler;
    session.Network.Enable(new EnableCommandSettings());
    
    public void ResponseReceivedHandler(object sender, ResponseReceivedEventArgs e)
    {
       Debug.WriteLine($"Status: { e.Response.Status } : {e.Response.StatusText} | File: 
       { e.Response.MimeType } | Url: { e.Response.Url } ");
    }
    

    我尝试了很多方法来弄清楚如何获得我想要的信息。 也许我的own question 得到了回答,直到你看到这个,我分享了我尝试过的所有内容。

    另外this guide 可以帮助您入门。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 2011-04-17
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      相关资源
      最近更新 更多