Accessing Network properties of open URL using Selenium Java

If you want to access the Header information, Request Payload and Response using Selenium, then it’s easy with Chrome.

All you have to do is to add following capabilities in the Chrome.

DesiredCapabilities cap =;
// logging prefs
LoggingPreferences loggingprefs = new LoggingPreferences();
loggingprefs.enable(LogType.BROWSER, Level.ALL);
loggingprefs.enable(LogType.CLIENT, Level.ALL);
loggingprefs.enable(LogType.PERFORMANCE, Level.ALL);
loggingprefs.enable(LogType.PROFILER, Level.ALL);
cap.setCapability(CapabilityType.LOGGING_PREFS, loggingprefs);

// Creating Chrome options
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability("goog:loggingPrefs", loggingprefs);
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

Webdriver driver =  driver = new ChromeDriver(chromeOptions);

// Add following methods to call logging

 public void logBrowserConsoleLogs(WebDriver driver) {
        all(LogType.PERFORMANCE, driver);

    public void all(String logTypes, WebDriver driver) {
        String var;
        String authorizationtoken = "";
        String host = "";
        List<LogEntry> logEntries = driver.manage().logs().get(logTypes).getAll();
        for (LogEntry entry : logEntries) {
            var = new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " +   entry.getMessage();
        System.out.println("DeubiAuthorizationToken: " + authorizationtoken);
        System.out.println("DeubiAuthorizationHost" + host);

logBrowserConsoleLogs(); will print all the logs on the console. Now you can play with the parameters you need from the Network tab, which you mostly use for manual testing to see what’s happening on the page.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s