Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Selenium2Library/locators/elementfinder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import copy

from robot.api import logger
from robot.utils import NormalizedDict
from selenium.webdriver.remote.webelement import WebElement
Expand Down Expand Up @@ -29,6 +31,7 @@ def __init__(self, ctx):
self._strategies = NormalizedDict(initial=strategies, caseless=True,
spaceless=True)
self._default_strategies = list(strategies)
self._original_strategies = copy.deepcopy(self._default_strategies)
self._key_attrs = {
None: ['@id', '@name'],
'a': ['@id', '@name', '@href',
Expand All @@ -48,7 +51,10 @@ def find(self, locator, tag=None, first_only=True, required=True):
"is not supported." % prefix)
strategy = self._strategies.get(prefix)
tag, constraints = self._get_tag_and_constraints(tag)
elements = strategy(criteria, tag, constraints)
if prefix in self._original_strategies:
elements = strategy(criteria, tag, constraints)
else:
elements = strategy(self.browser, criteria, tag, constraints)
if required and not elements:
raise ValueError("Element locator '{}' did not match any "
"elements.".format(locator))
Expand Down
5 changes: 1 addition & 4 deletions test/acceptance/locators/custom.robot
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ Ensure Locators Can Persist
*** Keywords ***
Setup Custom Locator
[Arguments] ${persist}=${EMPTY}
[Documentation] Setup Custom Locator
Add Location Strategy custom Custom Locator Strategy persist=${persist}

Teardown Custom Locator
[Documentation] Teardown Custom Locator
Remove Location Strategy custom

Custom Locator Strategy
[Arguments] ${criteria} ${tag} ${constraints}
[Documentation] Custom Locator Strategy
[Arguments] ${browser} ${criteria} ${tag} ${constraints}
${retVal}= Execute Javascript return window.document.getElementById('${criteria}') || [];
[Return] ${retVal}