From 50a2964f1686395f0936d78a6fa6e94386abbcba Mon Sep 17 00:00:00 2001 From: Gaurang Shah Date: Thu, 13 Oct 2016 18:28:38 +0530 Subject: [PATCH 1/3] Added method to find element by class name #673 --- src/Selenium2Library/__init__.py | 1 + src/Selenium2Library/locators/elementfinder.py | 6 ++++++ test/unit/locators/test_elementfinder.py | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Selenium2Library/__init__.py b/src/Selenium2Library/__init__.py index 145258091..bd23f053b 100644 --- a/src/Selenium2Library/__init__.py +++ b/src/Selenium2Library/__init__.py @@ -70,6 +70,7 @@ class Selenium2Library( | link | Click Element `|` link=My Link | Matches anchor elements by their link text | | partial link | Click Element `|` partial link=y Lin | Matches anchor elements by their partial link text | | css | Click Element `|` css=div.my_class | Matches by CSS selector | + | class | Click Element `|` class=my_class | Matches by class name selector | | jquery | Click Element `|` jquery=div.my_class | Matches by jQuery/sizzle selector | | sizzle | Click Element `|` sizzle=div.my_class | Matches by jQuery/sizzle selector | | tag | Click Element `|` tag=div | Matches by HTML tag name | diff --git a/src/Selenium2Library/locators/elementfinder.py b/src/Selenium2Library/locators/elementfinder.py index 81da96539..6bc0496e9 100644 --- a/src/Selenium2Library/locators/elementfinder.py +++ b/src/Selenium2Library/locators/elementfinder.py @@ -15,6 +15,7 @@ def __init__(self): 'link': self._find_by_link_text, 'partial link': self._find_by_partial_link_text, 'css': self._find_by_css_selector, + 'class': self._find_by_class_name, 'jquery': self._find_by_sizzle_selector, 'sizzle': self._find_by_sizzle_selector, 'tag': self._find_by_tag_name, @@ -108,6 +109,11 @@ def _find_by_css_selector(self, browser, criteria, tag, constraints): browser.find_elements_by_css_selector(criteria), tag, constraints) + def _find_by_class_name(self, browser, criteria, tag, constraints): + return self._filter_elements( + browser.find_elements_by_class_name(criteria), + tag, constraints) + def _find_by_tag_name(self, browser, criteria, tag, constraints): return self._filter_elements( browser.find_elements_by_tag_name(criteria), diff --git a/test/unit/locators/test_elementfinder.py b/test/unit/locators/test_elementfinder.py index 28505f1d1..fba91e30e 100644 --- a/test/unit/locators/test_elementfinder.py +++ b/test/unit/locators/test_elementfinder.py @@ -271,7 +271,6 @@ def test_find_by_partial_link_text(self): result = finder.find(browser, "partial link=my link", tag='a') self.assertEqual(result, [elements[1], elements[3]]) - def test_find_by_css_selector(self): finder = ElementFinder() browser = mock() @@ -284,6 +283,18 @@ def test_find_by_css_selector(self): result = finder.find(browser, "css=#test1", tag='a') self.assertEqual(result, [elements[1], elements[3]]) + def test_find_by_class_names(self): + finder = ElementFinder() + browser = mock() + + elements = self._make_mock_elements('div', 'a', 'span', 'a') + when(browser).find_elements_by_class_name("test1").thenReturn(elements) + + result = finder.find(browser, "class=test1") + self.assertEqual(result, elements) + result = finder.find(browser, "class=test1", tag='a') + self.assertEqual(result, [elements[1], elements[3]]) + def test_find_by_tag_name(self): finder = ElementFinder() browser = mock() From 4ac59c648be5f3dca2a7e112c71bbf42629eb77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lio=20Guilherme?= Date: Fri, 14 Oct 2016 13:41:42 +0100 Subject: [PATCH 2/3] Changes to use Firefox ESR (45.4.0) While we are not having Selenium 3.0 working, with external `geckodriver`, we use lower versions of stable Firefox. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d9b956d00..b1ca3f66a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +addons: + firefox: latest-esr language: python sudo: false python: From 2c607c521af9ce4e5db9919805dabf48901a3073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lio=20Guilherme?= Date: Fri, 14 Oct 2016 13:45:35 +0100 Subject: [PATCH 3/3] Changes to use Selenium 2.53.6 (and not 3.0) We are not ready for Selenium 3.0 yet. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b1ca3f66a..92e5beafa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ install: #- pip install pep8 --use-mirrors #- pip install pyflakes --use-mirrors - pip install robotframework - - pip install selenium + - pip install selenium==2.53.6 - pip install decorator - pip install mockito #- "if [[ ${BROWSER} == 'ie' ]]; then pip install ie_only_pkg; fi"