Skip to content

Commit

Permalink
Fix select_by_visible_test to raise an exception on hidden options ev…
Browse files Browse the repository at this point in the history
…en if the argument text has spaces

Fix error messages to be the same as java's one
  • Loading branch information
FFederi committed Jan 24, 2025
1 parent f8fbbb6 commit e44caff
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions py/selenium/webdriver/support/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def select_by_visible_text(self, text: str) -> None:
matched = False
for opt in opts:
if not self._has_css_property_and_visible(opt):
raise NoSuchElementException(f"Could not locate element with visible text: {text}")
raise NoSuchElementException(f"Invisible option with text: {text}")
self._set_selected(opt)
if not self.is_multiple:
return
Expand All @@ -130,6 +130,8 @@ def select_by_visible_text(self, text: str) -> None:
candidates = self._el.find_elements(By.XPATH, xpath)
for candidate in candidates:
if text == candidate.text:
if not self._has_css_property_and_visible(candidate):
raise NoSuchElementException(f"Invisible option with text: {text}")
self._set_selected(candidate)
if not self.is_multiple:
return
Expand Down Expand Up @@ -205,7 +207,7 @@ def deselect_by_visible_text(self, text: str) -> None:
opts = self._el.find_elements(By.XPATH, xpath)
for opt in opts:
if not self._has_css_property_and_visible(opt):
raise NoSuchElementException(f"Could not locate element with visible text: {text}")
raise NoSuchElementException(f"Invisible option with text: {text}")
self._unset_selected(opt)
matched = True
if not matched:
Expand Down

0 comments on commit e44caff

Please sign in to comment.