From 7da139ab2b6da64b04bfac92d89a700fddce2e57 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Thu, 22 Jun 2017 00:26:40 +0300 Subject: [PATCH] Provides fix to keep API for adding custom locator strategy --- src/Selenium2Library/locators/elementfinder.py | 8 +++++++- test/acceptance/locators/custom.robot | 5 +---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Selenium2Library/locators/elementfinder.py b/src/Selenium2Library/locators/elementfinder.py index 94639e783..330618cb7 100644 --- a/src/Selenium2Library/locators/elementfinder.py +++ b/src/Selenium2Library/locators/elementfinder.py @@ -1,3 +1,5 @@ +import copy + from robot.api import logger from robot.utils import NormalizedDict from selenium.webdriver.remote.webelement import WebElement @@ -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', @@ -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)) diff --git a/test/acceptance/locators/custom.robot b/test/acceptance/locators/custom.robot index 4e65b3a4d..bebf06a29 100644 --- a/test/acceptance/locators/custom.robot +++ b/test/acceptance/locators/custom.robot @@ -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}