Skip to content

Commit 4efcb9c

Browse files
committed
Merge pull request #405 from zephraph/locator-methods
Allows custom locators to be regular methods
2 parents ea384de + b8c5c70 commit 4efcb9c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Selenium2Library/locators/customlocator.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77

88
class CustomLocator(object):
99

10-
def __init__(self, name, keyword):
10+
def __init__(self, name, finder):
1111
self.name = name
12-
self.keyword = keyword
12+
self.finder = finder
1313

1414
def find(self, *args):
15-
element = BuiltIn().run_keyword(self.keyword, *args)
15+
16+
# Allow custom locators to be keywords or normal methods
17+
if isinstance(self.finder, string_type):
18+
element = BuiltIn().run_keyword(self.finder, *args)
19+
elif hasattr(self.finder, '__caller__'):
20+
element = self.finder(*args)
21+
else:
22+
raise AttributeError('Invalid type provided for Custom Locator %s' % self.name)
23+
24+
# Always return an array
1625
if hasattr(element, '__len__') and (not isinstance(element, string_type)):
1726
return element
1827
else:

0 commit comments

Comments
 (0)