Skip to content

Instantly share code, notes, and snippets.

@yeukhon
Last active August 29, 2015 14:04
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 yeukhon/f4d3618797e846a702f0 to your computer and use it in GitHub Desktop.
Save yeukhon/f4d3618797e846a702f0 to your computer and use it in GitHub Desktop.
Basic alert detection using selenium-webdriver.
<html>
<body>
<script>alert("xssssss");</script>
</body>
</html>
<html></html>
var webdriver = require('selenium-webdriver');
const SError = webdriver.error.ErrorCode;
var Q = require('q');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
driver.get('http://localhost:8000/bad.html');
driver.switchTo().alert().getText().then(
function(text) {
console.log("alert detected");
console.log(text);
},
function() {
console.log("alert not detected");
})
.then(function() {
console.log("quitting...");
driver.quit();
});
var driver2 = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
driver2.get('http://localhost:8000/good.html');
driver2.switchTo().alert().then(
function(text) {
console.log("alert detected");
console.log(text);
},
function(e) {
if (e.code !== SError.NO_MODAL_DIALOG_OPEN) {
throw e;
} else {
console.log("alert not detected");
}})
.then(function() {
console.log("quitting...");
driver2.quit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment