Created
October 31, 2013 18:58
-
-
Save umaar/7254974 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/*global console */ | |
/* | |
* In this file, we do a search for two non-existent selectors | |
* However the failure of only one of them contains the error we actually want | |
*/ | |
(function() { | |
"use strict"; | |
var webdriver = require('selenium-webdriver'); | |
var driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build(); | |
webdriver.promise.controlFlow().on('uncaughtException', function(e) { | |
/* | |
* Much better logging here, starts with: "NoSuchElementError: no such element" | |
* <stack trace> | |
* ==== async task ==== | |
* WebDriver.findElement(By.cssSelector(".non-existent2")) | |
* ^ bingo | |
*/ | |
console.error('\n' + e.stack); | |
}); | |
function handleError(err) { | |
//NoSuchElementError: no such element - there is no selector information however | |
console.log('\nError with findElement', err.stack); | |
} | |
driver.manage().window().setSize(1280, 720).then(function() { | |
driver.get('http://www.google.com'); | |
driver.findElement(webdriver.By.css('.non-existent1')).then(null, handleError); | |
// Notice how 'uncaughtException' is triggered resulting in much improved logging | |
driver.findElement(webdriver.By.css('.non-existent2')).then(null); | |
driver.quit(); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment