Skip to content

Instantly share code, notes, and snippets.

@javascriptlove
Last active March 2, 2017 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javascriptlove/4a00c4931c4c83287f4efd6c23fd02ed to your computer and use it in GitHub Desktop.
Save javascriptlove/4a00c4931c4c83287f4efd6c23fd02ed to your computer and use it in GitHub Desktop.
Getting http response code with Selenium and Expose Response Headers extension
// uses Expose Response Headers extension for Chrome
var builder = new selenium.Builder().withCapabilities(selenium.Capabilities.chrome());
var options = new selenium_chrome.Options();
options.addExtensions(__dirname + "/response-headers.crx");
builder.setChromeOptions(options);
var page = builder.build();
page.then(function() {
page.get(url).then(function() {
page.executeScript(function() {
return {
statusCode: navigator.responseStatusCode
}
}).then(function(obj) {
// now you have obj.statusCode
});
}, function(err) {
// error opening url
});
}, function(err) {
// error creating browser
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment