def perform_as(self, the_actor: Actor) -> None: """ Asks the actor to attempt to find the dropdown element described by the stored target, then performs the select action. Args: the_actor: The |Actor| who will perform the action. Raises: |DeliveryError|: an exception was raised by Selenium. |UnableToActError|: no target was supplied. |UnableToPerformError|: the actor does not have the ability to |BrowseTheWeb|. """ if self.target is None: raise UnableToActError( "Target was not provided for SelectByIndex. Provide a target using the " ".from_() or .from_the() methods.") element = self.target.found_by(the_actor) select = SeleniumSelect(element) try: select.select_by_index(self.index) except WebDriverException as e: msg = ( "Encountered an issue while attempting to select the option at index " f"{self.index} from {self.target}: {e.__class__.__name__}") raise DeliveryError(msg).with_traceback(e.__traceback__)
def perform_as(self, the_actor: Actor) -> None: """ Direct the actor to select the chosen option from the targeted dropdown or multiselect field. Args: the_actor: The |Actor| who will perform the action. Raises: |DeliveryError|: an exception was raised by Selenium. |UnableToAct|: no target was supplied. |UnableToPerform|: the actor does not have the ability to |BrowseTheWeb|. """ if self.target is None: raise UnableToAct( "Target was not provided for SelectByValue. Provide a target using the " ".from_() or .from_the() methods.") element = self.target.found_by(the_actor) select = SeleniumSelect(element) try: select.select_by_value(self.value) except WebDriverException as e: msg = ( "Encountered an issue while attempting to select the option with value " f"{self.value} from {self.target}: {e.__class__.__name__}") raise DeliveryError(msg).with_traceback(e.__traceback__)
def answered_by(self, the_actor: Actor) -> Union[str, List[str]]: """ Direct the actor to name the selected option(s). Args: the_actor: the |Actor| who will answer the question. Returns: str: the text of the single option selected in a dropdown, or the first option selected in a multi-select field. List[str]: the text of all options selected in a multi-select field. """ select = SeleniumSelect(self.target.found_by(the_actor)) if self.multi: return [e.text for e in select.all_selected_options] return select.first_selected_option.text
def answered_by(self, the_actor: Actor) -> Union[str, List[str]]: """ Asks the supplied actor to investigate the page and give their answer. Args: the_actor: the |Actor| who will answer the question. Returns: str: the text of the single option selected in a dropdown, or the first option selected in a multi-select field. List[str]: the text of all options selected in a multi-select field. """ select = SeleniumSelect(self.target.found_by(the_actor)) if self.multi: return [e.text for e in select.all_selected_options] return select.first_selected_option.text
def selenium_select(self): """Return Selenium select object to call other select methods, like select_by_index, deselect_by_index... :returns: Selenium select object """ return SeleniumSelect(self.web_element)