• <small id='udIYS'></small><noframes id='udIYS'>

      <legend id='udIYS'><style id='udIYS'><dir id='udIYS'><q id='udIYS'></q></dir></style></legend>

      • <bdo id='udIYS'></bdo><ul id='udIYS'></ul>
        <i id='udIYS'><tr id='udIYS'><dt id='udIYS'><q id='udIYS'><span id='udIYS'><b id='udIYS'><form id='udIYS'><ins id='udIYS'></ins><ul id='udIYS'></ul><sub id='udIYS'></sub></form><legend id='udIYS'></legend><bdo id='udIYS'><pre id='udIYS'><center id='udIYS'></center></pre></bdo></b><th id='udIYS'></th></span></q></dt></tr></i><div id='udIYS'><tfoot id='udIYS'></tfoot><dl id='udIYS'><fieldset id='udIYS'></fieldset></dl></div>
        <tfoot id='udIYS'></tfoot>
      1. 无法在 Selenium C# 中获取 Chrome 性能日志

        时间:2023-09-14
          • <legend id='SnTHW'><style id='SnTHW'><dir id='SnTHW'><q id='SnTHW'></q></dir></style></legend>
              <tbody id='SnTHW'></tbody>
            <tfoot id='SnTHW'></tfoot>
              <bdo id='SnTHW'></bdo><ul id='SnTHW'></ul>

                <i id='SnTHW'><tr id='SnTHW'><dt id='SnTHW'><q id='SnTHW'><span id='SnTHW'><b id='SnTHW'><form id='SnTHW'><ins id='SnTHW'></ins><ul id='SnTHW'></ul><sub id='SnTHW'></sub></form><legend id='SnTHW'></legend><bdo id='SnTHW'><pre id='SnTHW'><center id='SnTHW'></center></pre></bdo></b><th id='SnTHW'></th></span></q></dt></tr></i><div id='SnTHW'><tfoot id='SnTHW'></tfoot><dl id='SnTHW'><fieldset id='SnTHW'></fieldset></dl></div>

                <small id='SnTHW'></small><noframes id='SnTHW'>

                  本文介绍了无法在 Selenium C# 中获取 Chrome 性能日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的解决方案中使用以下 nuget 包

                  I am using following nuget packages in my solution

                  1. Selenium.WebDriver - v3.141.0
                  2. Selenium.WebDriver.ChromeDriver - v79.0.3945.3600

                  我正在使用以下代码创建 Chrome 驱动程序实例

                  using following code I am creating a Chrome driver instance

                  ChromeOptions options = new ChromeOptions();
                  
                  //Get Performance Logs from Network tab
                  ChromePerformanceLoggingPreferences perfLogPrefs = new ChromePerformanceLoggingPreferences();
                  options.PerformanceLoggingPreferences = perfLogPrefs;
                  options.SetLoggingPreference("performance", LogLevel.All);
                  

                  (或)

                  ChromePerformanceLoggingPreferences perfLogPrefs = new 
                  ChromePerformanceLoggingPreferences();
                  perfLogPrefs.AddTracingCategories(new string[] { "devtools.timeline" });
                  options.PerformanceLoggingPreferences = perfLogPrefs;
                  options.SetLoggingPreference("goog:loggingPrefs", LogLevel.All);
                  options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
                  

                  并与此结合

                  options.AddUserProfilePreference("intl.accept_languages", "en-US");
                  options.AddUserProfilePreference("disable-popup-blocking", "true");
                  options.AddArgument("test-type");
                  options.AddArgument("--disable-gpu");
                  options.AddArgument("no-sandbox");
                  options.AddArgument("start-maximized");
                  options.LeaveBrowserRunning = true;
                  
                  IWebDriver driver = new ChromeDriver(options);
                  

                  但在创建 Chrome 驱动程序实例时,我收到以下错误消息

                  but while creating Chrome driver instance, I am getting following error message

                  无效参数:'firstMatch' 的条目 0 无效来自无效参数:指定了 perfLoggingPrefs,但未启用性能日志记录

                  请问我需要进行哪些更改才能使用最新版本的 Chrome 和 Selenium 驱动程序获取性能日志

                  May I know what changes do I need to make please to get the performance logs with latest version of Chrome and Selenium driver

                  当我使用较低版本的 Chrome 驱动程序 (2.35.0) 时,我可以使用以下代码检索性能日志

                  I am able to retrieve Performance Logs using the below code when I was using lower versions of Chrome driver (2.35.0)

                  var logs = driver.Manage().Logs.GetLog("performance");
                  
                  for (int i = 0; i < logs.Count; i++)
                  {
                     Console.WriteLine(logs[i].Message);
                  }
                  

                  推荐答案

                  使用 Selenium WebDriver (v4.0.0-alpha04) 和 Selenium.Chrome.WebDriver (v79.0.0) 并使用以下代码,我能够检索性能日志.

                  With Selenium WebDriver (v4.0.0-alpha04) and Selenium.Chrome.WebDriver (v79.0.0) and using the following code, I am able to retrieve the performance logs.

                  ChromeOptions options = new ChromeOptions();
                  
                  //Following Logging preference helps in enabling the performance logs
                  options.SetLoggingPreference("performance", LogLevel.All);
                  
                  //Based on your need you can change the following options
                  options.AddUserProfilePreference("intl.accept_languages", "en-US");
                  options.AddUserProfilePreference("disable-popup-blocking", "true");
                  options.AddArgument("test-type");
                  options.AddArgument("--disable-gpu");
                  options.AddArgument("no-sandbox");
                  options.AddArgument("start-maximized");
                  options.LeaveBrowserRunning = true;
                  
                  //Creating Chrome driver instance
                  IWebDriver driver = new ChromeDriver(options);
                  
                  //Extracting the performance logs
                  var logs = driver.Manage().Logs.GetLog("performance");
                  for (int i = 0; i < logs.Count; i++)
                  {
                     Console.WriteLine(logs[i].Message);
                  }
                  

                  希望这会有所帮助.

                  这些天来,我在最新版本的 Selenium WebDriver 和 Chrome 驱动程序中使用以下两行代码,但无法弄清楚问题所在,现在使用最新版本,不需要以下两行代码.

                  All these days, I was using the following two lines with latest versions of Selenium WebDriver and Chrome Driver and couldn't figure out what the issue was and now with the latest versions, the following two lines of code is not required.

                  var perfLogPrefs = new ChromePerformanceLoggingPreferences();
                  options.PerformanceLoggingPreferences = perfLogPrefs;
                  

                  这篇关于无法在 Selenium C# 中获取 Chrome 性能日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:“消息=未知错误:无法聚焦元素"通过 Selenium、ChromeDriver 和 Chrome 执行测试时 下一篇:使用 Selenium 在现有浏览器会话中打开一个新选项卡

                  相关文章

                  <small id='hkNhc'></small><noframes id='hkNhc'>

                      <bdo id='hkNhc'></bdo><ul id='hkNhc'></ul>
                  1. <legend id='hkNhc'><style id='hkNhc'><dir id='hkNhc'><q id='hkNhc'></q></dir></style></legend>

                    <tfoot id='hkNhc'></tfoot>
                    1. <i id='hkNhc'><tr id='hkNhc'><dt id='hkNhc'><q id='hkNhc'><span id='hkNhc'><b id='hkNhc'><form id='hkNhc'><ins id='hkNhc'></ins><ul id='hkNhc'></ul><sub id='hkNhc'></sub></form><legend id='hkNhc'></legend><bdo id='hkNhc'><pre id='hkNhc'><center id='hkNhc'></center></pre></bdo></b><th id='hkNhc'></th></span></q></dt></tr></i><div id='hkNhc'><tfoot id='hkNhc'></tfoot><dl id='hkNhc'><fieldset id='hkNhc'></fieldset></dl></div>