public int loadingFinishedCount(WebDriver driver){
LogEntries logs = driver.manage().logs().get("performance");
// System.out.println("\nList of log entries:\n");
int m=0;
for(Iterator<LogEntry> it = logs.iterator(); it.hasNext();){
LogEntry entry = it.next();
try{
JSONObject json = new JSONObject(entry.getMessage());
JSONObject message = json.getJSONObject("message");
// System.out.println(message);
String method = message.getString("method");
if(method!=null&&"Network.loadingFinished".equals(method)){
++m;
}
}catch (JSONException e){
e.printStackTrace();
}
}
return m;
}
public void pageLoadingFinished(WebDriver driver, int loadingFinishedCount){
loadingFinishedCount(driver);
// System.out.println(m);
for(double i=0; i<=1000; i=i+0.1) {
int n = loadingFinishedCount(driver);
// System.out.println(n);
if (n >=loadingFinishedCount) {
break;
}
}
}
reference:https://*.com/questions/6509628/how-to-get-http-response-code-using-selenium-webdriver-with-java