How can I capture network traffic of a specific page using Selenium

+1 vote
Jul 19, 2019 in Selenium by anonymous

1 answer to this question.

+2 votes

Hey, to capture network network traffic of a specific page using Selenium Webdriver:

public class CaptureNetworkTraffic {

public static WebDriver driver;
public static String driverPath = "C:\\\\Users\\\\Abha_Rathour\\\\Downloads\\\\ExtractedFiles\\\\chromedriver_win32\\\\chromedriver.exe";

public static void main(String[] args) {

System.setProperty("", driverPath);

DesiredCapabilities caps =;

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.INFO);

caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

driver= new ChromeDriver(caps);

List<LogEntry> entries = driver.manage().logs().get(LogType.PERFORMANCE).getAll();

System.out.println(entries.size() + " " + LogType.PERFORMANCE + " log entries found");

for (LogEntry entry : entries) {
    System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());




This will produce following output:

For further understanding, you can refer to the Selenium Course.

answered Jul 19, 2019 by Abha
• 28,140 points

hi my friend i use your code but it doesnt work how should i do?

Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument: log type 'performance' not found

  (Session info: chrome=76.0.3809.87)

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

System info: host: 'DESKTOP-BOLOAH3', ip: '', 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_212'

Driver info:

Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 76.0.3809.87, chrome: {chromedriverVersion: 76.0.3809.126 (d80a294506b4..., userDataDir: C:\Users\Mobin\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:1991}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}

Session ID: 31f02508307d36fbb666f0d4573cb6f2

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(

at java.lang.reflect.Constructor.newInstance(

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(

at org.openqa.selenium.remote.HttpCommandExecutor.execute(

at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(

at org.openqa.selenium.remote.RemoteWebDriver.execute(

at org.openqa.selenium.remote.RemoteExecuteMethod.execute(

at org.openqa.selenium.remote.RemoteLogs.getRemoteEntries(

at org.openqa.selenium.remote.RemoteLogs.get(

at main.main(
Hi Mobin, did you use the exactly same code or you changed something in it.
Yeah Im Sure, Which Version of JDK and Selenium do you use ?
I am using Selenium 3.9.1 version and JDK of 11.0.2 version.


For anyone coming to this recently - in recent Selenium and ChromeDriver versions (eg 3.14.159, chrome driver 76.x) setting up loggingPrefs with ChromeDriver doesn't seem to work, using the local ChromeDriver - no matter what you do you seem to get the log type 'performance' not found error

The reason is increasingly strict w3c spec compliance, both in Selenium and ChromeDriver code.

Instead of the loggingPrefs/CapabilityType.LOGGING_PREFS capability, you need to use goog:loggingPrefs, like so

    ChromeOptions options = new ChromeOptions();
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable( LogType.PERFORMANCE, Level.ALL );
    options.setCapability( "goog:loggingPrefs", logPrefs );

I guess that sooner or later the Selenium side will notice this and change the CapabilityType.LOGGING_PREFS constant or add a new one, but the project didn't look very friendly to log an issue with to me.

I solved this by following this thread:


Code works fine but log doesn't contain any information about ajax requests.Is there any possible way to include it? Thanks in advance.

Hello G3,

With this.driver.manage().logs().get(LogType.BROWSER).getAll() you should receive all logs that you can see in browser's console.

Related Questions In Selenium

0 votes
1 answer

How can I scroll a web page in Mozilla Firefox using Selenium?

Hi Rohan, steps to scroll a webpage in ...READ MORE

answered May 14, 2019 in Selenium by Pratibha
• 3,690 points
0 votes
1 answer

How can I locate web elements from a web page using Selenium Webdriver?

Hey @Dushyant, Locating elements in WebDriver is ...READ MORE

answered May 29, 2019 in Selenium by Shreya
0 votes
1 answer

How can I perform multiple selection of options in a dropdown using Select class in Selenium?

Hey Priyansh, you can select multiple options ...READ MORE

answered Jul 8, 2019 in Selenium by Anvi
• 14,150 points
0 votes
1 answer

How can I capture screenshot of a webpage partially in Selenium?

Hey Tejasvi, you can capture screenshot of ...READ MORE

answered Jul 8, 2019 in Selenium by Anvi
• 14,150 points
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

How can I get meta-description of a webpage using Selenium Webdriver?

Hey Sonal, to get the meta-description of ...READ MORE

answered Jul 23, 2019 in Selenium by Abha
• 28,140 points
0 votes
1 answer

How can I locate inline elements from a web page using Selenium Webdriver?

Which specific element you are trying to ...READ MORE

answered Oct 10, 2019 in Selenium by Abha
• 28,140 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP