Last active
August 29, 2015 14:04
-
-
Save yeukhon/f4d3618797e846a702f0 to your computer and use it in GitHub Desktop.
Basic alert detection using selenium-webdriver.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script>alert("xssssss");</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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