I'm currently working on automating a website and I need to identify which JavaScript files are being called for specific URLs. Is there a way to retrieve the names of JS files that are used or called by a webpage? Typically, I am looking for the names of JS files listed under Developers Tool > Network > JS tab. You can see an example image of what I want to capture here (Sample image of Stackoverflow homepage).
I have attempted to achieve this using the following code:
DesiredCapabilities d = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
d.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
WebDriver driver = new ChromeDriver(d);
driver.get("https://stackoverflow.com");
LogEntries logs = driver.manage().logs().get(LogType.SERVER);
for (LogEntry log : logs) {
System.out.println(log.getMessage());
}
However, this code provides more details than needed. Is there a way to extract only the names of the JavaScript files?