// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617goog.provide('bot.locators.name');1819goog.require('bot.dom');20goog.require('goog.array');21goog.require('goog.dom');222324/**25* Find an element by the value of the name attribute26*27* @param {string} target The name to search for.28* @param {!(Document|Element)} root The document or element to perform the29* search under.30* @return {Element} The first matching element found in the DOM, or null if no31* such element could be found.32*/33bot.locators.name.single = function (target, root) {34var dom = goog.dom.getDomHelper(root);35var allElements = dom.getElementsByTagNameAndClass('*', null, root);36var element = goog.array.find(allElements, function (element) {37return bot.dom.getAttribute(element, 'name') == target;38});39return /**@type{Element}*/ (element);40};414243/**44* Find all elements by the value of the name attribute45*46* @param {string} target The name to search for.47* @param {!(Document|Element)} root The document or element to perform the48* search under.49* @return {!IArrayLike} All matching elements, or an empty list.50*/51bot.locators.name.many = function (target, root) {52var dom = goog.dom.getDomHelper(root);53var allElements = dom.getElementsByTagNameAndClass('*', null, root);54return goog.array.filter(allElements, function (element) {55return bot.dom.getAttribute(element, 'name') == target;56});57};585960