Skip to content

Commit 3989a0c

Browse files
aaltatpekkaklarck
authored andcommitted
Fixes robotframework#629 by expecting NoSuchElementException (robotframework#630)
* Fixes robotframework#629 by expecting NoSuchElementException Empty expect are not coding practices. The deselect_by_value and the deselect_by_visible_text raises NoSuchElementException if it can not deselect the items.
1 parent 90610dd commit 3989a0c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/Selenium2Library/keywords/_selectelement.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from selenium.webdriver.support.ui import Select
22
from keywordgroup import KeywordGroup
3+
from selenium.common.exceptions import NoSuchElementException
4+
35

46
class _SelectElementKeywords(KeywordGroup):
57

@@ -271,17 +273,16 @@ def unselect_from_list(self, locator, *items):
271273

272274
select, options = self._get_select_list_options(select)
273275
for item in items:
276+
# Only Selenium 2.52 and newer raise exceptions when there is no match.
277+
# For backwards compatibility reasons we want to ignore them.
274278
try:
275279
select.deselect_by_value(item)
276-
# Code for selenium <= 2.52.0
280+
except NoSuchElementException:
281+
pass
282+
try:
277283
select.deselect_by_visible_text(item)
278-
except: # Code for selenium > 2.52.0
279-
try:
280-
select.deselect_by_visible_text(item)
281-
except:
282-
self._warn("Tried to unselect missing selection item, \
283-
'%s' from locator '%s'." % (item, locator))
284-
continue
284+
except NoSuchElementException:
285+
pass
285286

286287
def unselect_from_list_by_index(self, locator, *indexes):
287288
"""Unselects `*indexes` from list identified by `locator`

0 commit comments

Comments
 (0)