Robot Framework SeleniumLibrary
customlocator.py
Go to the documentation of this file.
1 # Copyright 2008-2011 Nokia Networks
2 # Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors
3 # Copyright 2016- Robot Framework Foundation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # 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, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 from robot.libraries.BuiltIn import BuiltIn
18 
19 from SeleniumLibrary.base import ContextAware
20 
21 
22 try:
23  basestring
24 except NameError:
25  basestring = str
26 
27 
29 
30  def __init__(self, ctx, name, finder):
31  ContextAware.__init__(self, ctx)
32  self.namename = name
33  self.finderfinder = finder
34 
35  def find(self, criteria, tag, constraints, parent):
36  # Allow custom locators to be keywords or normal methods
37  if isinstance(self.finderfinder, basestring):
38  element = BuiltIn().run_keyword(self.finderfinder, parent,
39  criteria, tag, constraints)
40  elif hasattr(self.finderfinder, '__call__'):
41  element = self.finderfinder(parent, criteria, tag, constraints)
42  else:
43  raise AttributeError('Invalid type provided for Custom Locator %s'
44  % self.namename)
45 
46  # Always return an array
47  if hasattr(element, '__len__') and not isinstance(element, basestring):
48  return element
49  else:
50  return [element]
def find(self, criteria, tag, constraints, parent)