diff --git a/src/SeleniumLibrary/locators/elementfinder.py b/src/SeleniumLibrary/locators/elementfinder.py index d74486a3e..e48f63f87 100644 --- a/src/SeleniumLibrary/locators/elementfinder.py +++ b/src/SeleniumLibrary/locators/elementfinder.py @@ -223,7 +223,7 @@ def _find_by_tag_name(self, criteria, tag, constraints, parent): def _find_by_data_locator(self, criteria, tag, constraints, parent): try: - name, value = criteria.split(":", 2) + name, value = criteria.split(":", 1) if "" in [name, value]: raise ValueError except ValueError: diff --git a/utest/test/locators/test_elementfinder.py b/utest/test/locators/test_elementfinder.py index ed7b801bd..50472be20 100644 --- a/utest/test/locators/test_elementfinder.py +++ b/utest/test/locators/test_elementfinder.py @@ -283,6 +283,13 @@ def test_find_with_data(finder): finder.find("data:id:my_id", tag="div", required=False) verify(driver).find_elements(By.XPATH, '//*[@data-id="my_id"]') +def test_find_with_data_multiple_colons(finder): + driver = _get_driver(finder) + elements = _make_mock_elements("div", "a", "span", "a") + when(driver).find_elements(By.XPATH, '//*[@data-automation-id="foo:bar"]').thenReturn(elements) + result = finder.find("data:automation-id:foo:bar", first_only=False) + assert result == elements + def test_find_with_invalid_data(finder): with pytest.raises( @@ -297,6 +304,12 @@ def test_find_with_invalid_data(finder): ): finder.find("data:", tag="div", required=False) + with pytest.raises( + ValueError, + match=r"^Provided selector \(:value\) is malformed\. Correct format: name:value\.", + ): + finder.find("data::value", tag="div", required=False) + def test_find_with_locator_with_apos(finder): driver = _get_driver(finder)