Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interact with Developer tools in chrome using selenium or any other library

Tags:

selenium

I am trying to read or interact with network and console tabs of developer tools in chrome. Could you please guide me how to achieve this.

Thanks

like image 671
RSingh Avatar asked Dec 31 '25 08:12

RSingh


1 Answers

The short answer is no. How to open Chrome Developer console in Selenium WebDriver using JAVA. As the provided link states you cannot directly access the chrome developer tools.

But if you are interested in access the contents of the browser console and network tab, selenium provides you a way.

System.setProperty("webdriver.chrome.driver", getChromeDriverLocation());

LoggingPreferences loggingprefs = new LoggingPreferences();
loggingprefs.enable(LogType.BROWSER, Level.WARNING);
loggingprefs.enable(LogType.PERFORMANCE, Level.WARNING);

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingprefs);

driver = new ChromeDriver(capabilities);

You can then print the logs as needed

LogEntries logEntries = SeleniumBaseTest.getWebDriver().manage().logs()
            .get(org.openqa.selenium.logging.LogType.BROWSER);
for (LogEntry entry : logEntries) {
    System.out.println((String.format("%s %s %s\n", new Date(entry.getTimestamp()), entry.getLevel(),
                entry.getMessage())));
}

LogType.BROWSER will give you the browser console. Logtype.PERFROMANCE will give you the network tab.

Other ways to access the network tab is to use a browser proxy to record the transactions. http://www.seleniumeasy.com/selenium-tutorials/browsermob-proxy-selenium-example

like image 113
Sighil Avatar answered Jan 04 '26 14:01

Sighil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!