Skip to content

Commit 622ded1

Browse files
committed
Fix select_by_visible_test to raise an exception on hidden options even if the argument text has spaces
Fix error messages to be the same as java's one
1 parent ed154a0 commit 622ded1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

py/selenium/webdriver/support/select.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def select_by_visible_text(self, text: str) -> None:
115115
matched = False
116116
for opt in opts:
117117
if not self._has_css_property_and_visible(opt):
118-
raise NoSuchElementException(f"Could not locate element with visible text: {text}")
118+
raise NoSuchElementException(f"Invisible option with text: {text}")
119119
self._set_selected(opt)
120120
if not self.is_multiple:
121121
return
@@ -130,6 +130,8 @@ def select_by_visible_text(self, text: str) -> None:
130130
candidates = self._el.find_elements(By.XPATH, xpath)
131131
for candidate in candidates:
132132
if text == candidate.text:
133+
if not self._has_css_property_and_visible(candidate):
134+
raise NoSuchElementException(f"Invisible option with text: {text}")
133135
self._set_selected(candidate)
134136
if not self.is_multiple:
135137
return
@@ -205,7 +207,7 @@ def deselect_by_visible_text(self, text: str) -> None:
205207
opts = self._el.find_elements(By.XPATH, xpath)
206208
for opt in opts:
207209
if not self._has_css_property_and_visible(opt):
208-
raise NoSuchElementException(f"Could not locate element with visible text: {text}")
210+
raise NoSuchElementException(f"Invisible option with text: {text}")
209211
self._unset_selected(opt)
210212
matched = True
211213
if not matched:

0 commit comments

Comments
 (0)