diff --git a/py/selenium/webdriver/support/select.py b/py/selenium/webdriver/support/select.py index f33faaedf718a..31f68825682d7 100644 --- a/py/selenium/webdriver/support/select.py +++ b/py/selenium/webdriver/support/select.py @@ -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 @@ -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 @@ -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: