gecko/toolkit/components/passwordmgr/test/pwmgr_common.js

32 lines
832 B
JavaScript

/*
* $_
*
* Returns the element with the specified |name| attribute.
*/
function $_(formNum, name) {
var form = document.getElementById("form" + formNum);
if (!form) {
logWarning("$_ couldn't find requested form " + formNum);
return null;
}
var element = form.elements.namedItem(name);
if (!element) {
logWarning("$_ couldn't find requested element " + name);
return null;
}
// Note that namedItem is a bit stupid, and will prefer an
// |id| attribute over a |name| attribute when looking for
// the element. Login Mananger happens to use .namedItem
// anyway, but let's rigorously check it here anyway so
// that we don't end up with tests that mistakenly pass.
if (element.getAttribute("name") != name) {
logWarning("$_ got confused.");
return null;
}
return element;
}