diff --git a/src/SeleniumLibrary/locators/elementfinder.py b/src/SeleniumLibrary/locators/elementfinder.py
index 1b37c8cb7..99bb5297c 100644
--- a/src/SeleniumLibrary/locators/elementfinder.py
+++ b/src/SeleniumLibrary/locators/elementfinder.py
@@ -61,10 +61,7 @@ def find(self, locator, tag=None, first_only=True, required=True):
if isinstance(locator, WebElement):
return locator
prefix, criteria = self._parse_locator(locator)
- if prefix not in self._strategies:
- raise ValueError("Element locator with prefix '%s' "
- "is not supported." % prefix)
- strategy = self._strategies.get(prefix)
+ strategy = self._strategies[prefix]
tag, constraints = self._get_tag_and_constraints(tag)
elements = strategy(criteria, tag, constraints)
if required and not elements:
@@ -124,9 +121,6 @@ def unregister(self, strategy_name):
else:
del self._strategies[strategy_name]
- def has_strategy(self, strategy_name):
- return strategy_name in self.strategies
-
def _find_by_identifier(self, criteria, tag, constraints):
elements = self._normalize_result(
self.browser.find_elements_by_id(criteria))
@@ -257,10 +251,19 @@ def _get_tag_and_constraints(self, tag):
def _parse_locator(self, locator):
if locator.startswith(('//', '(//')):
return 'xpath', locator
+ index = self._get_locator_separator_index(locator)
+ if index != -1:
+ prefix = locator[:index].strip()
+ if prefix in self._strategies:
+ return prefix, locator[index+1:].lstrip()
+ return 'default', locator
+
+ def _get_locator_separator_index(self, locator):
if '=' not in locator:
- return 'default', locator
- prefix, criteria = locator.split('=', 1)
- return prefix.strip(), criteria.lstrip()
+ return locator.find(':')
+ if ':' not in locator:
+ return locator.find('=')
+ return min(locator.find('='), locator.find(':'))
def _element_matches(self, element, tag, constraints):
if not element.tag_name.lower() == tag:
diff --git a/test/acceptance/locators/locator_parsing.robot b/test/acceptance/locators/locator_parsing.robot
new file mode 100644
index 000000000..0d7acab85
--- /dev/null
+++ b/test/acceptance/locators/locator_parsing.robot
@@ -0,0 +1,37 @@
+*** Settings ***
+Documentation Tests different supported xpath strategies
+Test Setup Go To Page "links.html"
+Resource ../resource.robot
+
+*** Test Cases ***
+xpath with prefix should work
+ Page Should Contain Element xpath=//div[@id="div_id"]/a
+ Page Should Contain Element xpath://div[@id="div_id"]/a
+
+xpath with // and without prefix should work
+ Page Should Contain Element //div[@id="div_id"]/a
+
+xpath with (// and without prefix should work
+ Page Should Contain Element (//div[@id="div_id"]/a)[1]
+
+Locator without prefix
+ Page Should Contain Element div_id
+
+Locator with prefix
+ Page Should Contain Element id:div_id
+ Page Should Contain Element id=div_id
+ Page Should Contain Element id:foo:bar
+ Page Should Contain Element id=foo:bar
+ Page Should Contain Element id:bar=foo
+ Page Should Contain Element id=bar=foo
+
+Locator with separator but without matching prefix is not special
+ Page Should Contain Element foo:bar
+ Page Should Contain Element bar=foo
+
+Locator with separator and with matchign prefix cannot be used as-is
+ Page Should Contain Element id:id:problematic
+ Page Should Contain Element id=id:problematic
+ Run Keyword And Expect Error
+ ... Page should have contained element 'id:problematic' but did not
+ ... Page Should Contain Element id:problematic
diff --git a/test/acceptance/locators/xpath.robot b/test/acceptance/locators/xpath.robot
deleted file mode 100644
index 728501616..000000000
--- a/test/acceptance/locators/xpath.robot
+++ /dev/null
@@ -1,14 +0,0 @@
-*** Settings ***
-Documentation Tests different supported xpath strategies
-Test Setup Go To Page "links.html"
-Resource ../resource.robot
-
-*** Test Cases ***
-xpath with prefix should work
- Page Should Contain Element xpath=//div[@id="div_id"]/a
-
-xpath with // and without prefix should work
- Page Should Contain Element //div[@id="div_id"]/a
-
-xpath with (// and without prefix should work
- Page Should Contain Element (//div[@id="div_id"]/a)[1]
diff --git a/test/resources/html/links.html b/test/resources/html/links.html
index 183c3bb5c..bf9c0eafc 100644
--- a/test/resources/html/links.html
+++ b/test/resources/html/links.html
@@ -17,13 +17,13 @@
Link with asterisk * and another *
Link with Unicode äöüÄÖÜß
-