Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/atoms/locators/name.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
goog.provide('bot.locators.name');
19
20
goog.require('bot.dom');
21
goog.require('goog.array');
22
goog.require('goog.dom');
23
24
25
/**
26
* Find an element by the value of the name attribute
27
*
28
* @param {string} target The name to search for.
29
* @param {!(Document|Element)} root The document or element to perform the
30
* search under.
31
* @return {Element} The first matching element found in the DOM, or null if no
32
* such element could be found.
33
*/
34
bot.locators.name.single = function (target, root) {
35
var dom = goog.dom.getDomHelper(root);
36
var allElements = dom.getElementsByTagNameAndClass('*', null, root);
37
var element = goog.array.find(allElements, function (element) {
38
return bot.dom.getAttribute(element, 'name') == target;
39
});
40
return /**@type{Element}*/ (element);
41
};
42
43
44
/**
45
* Find all elements by the value of the name attribute
46
*
47
* @param {string} target The name to search for.
48
* @param {!(Document|Element)} root The document or element to perform the
49
* search under.
50
* @return {!IArrayLike} All matching elements, or an empty list.
51
*/
52
bot.locators.name.many = function (target, root) {
53
var dom = goog.dom.getDomHelper(root);
54
var allElements = dom.getElementsByTagNameAndClass('*', null, root);
55
return goog.array.filter(allElements, function (element) {
56
return bot.dom.getAttribute(element, 'name') == target;
57
});
58
};
59
60