From 9a4218f9ca100b5ac9588924eb1d19ff7d49bcfb Mon Sep 17 00:00:00 2001 From: adwu73 Date: Thu, 16 Aug 2012 14:42:08 +0800 Subject: [PATCH 1/3] add return False to (un)select from list... when nothing match --- src/Selenium2Library/keywords/_selectelement.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Selenium2Library/keywords/_selectelement.py b/src/Selenium2Library/keywords/_selectelement.py index df6405211..9bab854c5 100644 --- a/src/Selenium2Library/keywords/_selectelement.py +++ b/src/Selenium2Library/keywords/_selectelement.py @@ -186,6 +186,8 @@ def select_from_list(self, locator, *items): try: option_index = option_labels.index(item) except: continue select_func(select, options, option_index) + if not option_index: + return False def unselect_from_list(self, locator, *items): """Unselects given values from select list identified by locator. @@ -219,6 +221,8 @@ def unselect_from_list(self, locator, *items): try: option_index = option_labels.index(item) except: continue self._unselect_option_from_multi_select_list(select, options, option_index) + if not option_index: + return False # Private From 10ca7d148320cd33a252c10bf95faa16a797ce31 Mon Sep 17 00:00:00 2001 From: adwu73 Date: Thu, 16 Aug 2012 16:50:24 +0800 Subject: [PATCH 2/3] change from return False to raise error --- src/Selenium2Library/keywords/_selectelement.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Selenium2Library/keywords/_selectelement.py b/src/Selenium2Library/keywords/_selectelement.py index 9bab854c5..cd68b47bb 100644 --- a/src/Selenium2Library/keywords/_selectelement.py +++ b/src/Selenium2Library/keywords/_selectelement.py @@ -187,7 +187,7 @@ def select_from_list(self, locator, *items): except: continue select_func(select, options, option_index) if not option_index: - return False + raise ValueError("%s doesn't exist in list '%s'." % (items_str, locator)) def unselect_from_list(self, locator, *items): """Unselects given values from select list identified by locator. @@ -222,7 +222,7 @@ def unselect_from_list(self, locator, *items): except: continue self._unselect_option_from_multi_select_list(select, options, option_index) if not option_index: - return False + raise ValueError("%s doesn't exist in list '%s'." % (items_str, locator)) # Private From 0eb1049148ae7e6f06207338b66ca9be72e12dd0 Mon Sep 17 00:00:00 2001 From: adwu73 Date: Sat, 18 Aug 2012 21:12:39 +0800 Subject: [PATCH 3/3] change the condition to raise an exception --- src/Selenium2Library/keywords/_selectelement.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Selenium2Library/keywords/_selectelement.py b/src/Selenium2Library/keywords/_selectelement.py index cd68b47bb..261ead020 100644 --- a/src/Selenium2Library/keywords/_selectelement.py +++ b/src/Selenium2Library/keywords/_selectelement.py @@ -186,7 +186,7 @@ def select_from_list(self, locator, *items): try: option_index = option_labels.index(item) except: continue select_func(select, options, option_index) - if not option_index: + if option_index is None: raise ValueError("%s doesn't exist in list '%s'." % (items_str, locator)) def unselect_from_list(self, locator, *items): @@ -221,7 +221,7 @@ def unselect_from_list(self, locator, *items): try: option_index = option_labels.index(item) except: continue self._unselect_option_from_multi_select_list(select, options, option_index) - if not option_index: + if option_index is None: raise ValueError("%s doesn't exist in list '%s'." % (items_str, locator)) # Private