如何使用硒访问谷歌浏览器开发人员工具上的网络面板? [英] How to access Network panel on google chrome developer tools with selenium?

查看:32
本文介绍了如何使用硒访问谷歌浏览器开发人员工具上的网络面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得在开发者工具的网络面板上显示的输出.

I want to get the output that is shown on the network panel of the developer tools.

[网络面板 --> 名称、方法、状态、类型、发起者、大小、时间、时间线]

[Network panel --> Name, Method, Status, Type, Initiator, Size, Time, Timeline]

我需要这些信息.

推荐答案

这可以通过 Selenium WebDriver 实现.为此,您应该执行以下操作:

This possible via Selenium WebDriver. For this you should do the following:

  1. 从 - http://docs.seleniumhq.org/download/ 下载特定于 selenium 语言的客户端驱动程序并将适当的 jar 文件添加到您的项目构建路径中.

  1. Download selenium language-specific client drivers from - http://docs.seleniumhq.org/download/ and add apropriate jar files to your project build path.

要使用 Chrome/Chromium 运行测试,您还需要 chromdriver 二进制文件,您可以从 - http://chromedriver.storage.googleapis.com/index.html

To run a test with Chrome/Chromium you will also need chromdriver binary which you can download from - http://chromedriver.storage.googleapis.com/index.html

像这样创建一个测试用例:

Create a test case like this:

    // specify the path of the chromdriver binary that you have downloaded (see point 2)
    System.setProperty("webdriver.chrome.driver", "/root/Downloads/chromedriver");
    ChromeOptions options = new ChromeOptions();
    // if you like to specify another profile
    options.addArguments("user-data-dir=/root/Downloads/aaa"); 
    options.addArguments("start-maximized");
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver driver = new ChromeDriver(capabilities);
    driver.get("http://www.google.com");
    String scriptToExecute = "var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return network;";
    String netData = ((JavascriptExecutor)driver).executeScript(scriptToExecute).toString();

在 Chrome/Chromium 上执行 javascript 将帮助您获取网络(不仅)信息.生成的字符串netData"将包含 JSONArray 格式的所需数据.

Executing javascript on Chrome/Chromium will help you to get the networking (not only) info. The resulting string 'netData' will contain the required data in JSONArray format.

希望这会有所帮助.

这篇关于如何使用硒访问谷歌浏览器开发人员工具上的网络面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆