How to get transferred size of a complete page load?

I have achieved this in Python, which might save people some time. To setup the logging:

logging_prefs = {'performance' : 'INFO'}    
caps = DesiredCapabilities.CHROME.copy()
caps['loggingPrefs'] = logging_prefs
driver = webdriver.Chrome(desired_capabilities=caps)

To calculate the total:

total_bytes = []
for entry in driver.get_log('performance'):
        if "Network.dataReceived" in str(entry):
            r = re.search(r'encodedDataLength\":(.*?),', str(entry))
            total_bytes.append(int(r.group(1)))
            mb = round((float(sum(total_bytes) / 1000) / 1000), 2)

For future reference, it is possible to request this information from the browser by javascript. However, at the time of writing no browser supports this feature for this specific data yet. More information can be found here.

In the mean time, for Chrome you can parse this information from the performance log.

    //Enable performance logging
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    capa.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    //Start driver
    WebDriver driver = new ChromeDriver(capa);

You can then get this data like this

for (LogEntry entry : driver.manage().logs().get(LogType.PERFORMANCE)) {
        if(entry.getMessage().contains("Network.dataReceived")) {
            Matcher dataLengthMatcher = Pattern.compile("encodedDataLength\":(.*?),").matcher(entry.getMessage());
            dataLengthMatcher.find();
            //Do whatever you want with the data here.
        }

If, like in your case, you want to know the specifics of a single page load, you could use a pre- and postload timestamp and only get entries within that timeframe.


The performance API mentioned in Hakello's answer is now well supported (on everything except IE & Safari), and is simple to use:

return performance
  .getEntriesByType("resource")
  .map((x) => x.transferSize)
  .reduce((a, b) => (a + b), 0);

You can run that script using executeScript to get the number of bytes downloaded since the last navigation event. No setup or configuration is required.


Yes you can do it using BrowserMobProxy. This is a java jar which use selenium Proxy to track network traffic from client side. like page load time duration, Query string to different services etc. you can get it bmp.lightbody.net . This api will create .har files which will contain all these information in json format which you can read using an online tool http://www.softwareishard.com/har/viewer/