When a selector that we expect to match exactly one element matches multiple I want that to be an error instead of a warning to ensure the test author notices it.
Can we allow that to be configurable? Here is the code from element.js:
var getWebElements = function() {
return elementArrayFinder.getWebElements().then(function(webElements) {
if (webElements.length === 0) {
throw new webdriver.error.Error(
webdriver.error.ErrorCode.NO_SUCH_ELEMENT,
'No element found using locator: ' +
elementArrayFinder.locator_.toString());
} else {
if (webElements.length > 1) {
log.warn('more than one element found for locator ' +
elementArrayFinder.locator_.toString() +
' - the first result will be used');
}
return [webElements[0]];
}
});
};
We ended up adding a layer between our testing code and protractor, and we implemented our own error for this case.
@scriby Would you mind sharing your solution? I'd love to see this as a feature in Protractor. Having multiple elements selected and then simply using the first is asking for trouble.
Most helpful comment
@scriby Would you mind sharing your solution? I'd love to see this as a feature in Protractor. Having multiple elements selected and then simply using the first is asking for trouble.